﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / Table variables with calculated columns in UDFs bug? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 21:55:10 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Table variables with calculated columns in UDFs bug?</title><link>http://www.sqlservercentral.com/Forums/Topic256329-8-1.aspx</link><description>I have to admit I've not used calculations etc. in table variables, there are a number of "issues" with table variables which may or may not be a bug .. I assume your code works with a temp table.</description><pubDate>Wed, 10 May 2006 05:30:00 GMT</pubDate><dc:creator>colin.Leversuch-Roberts</dc:creator></item><item><title>RE: Table variables with calculated columns in UDFs bug?</title><link>http://www.sqlservercentral.com/Forums/Topic256329-8-1.aspx</link><description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;does anyone have any thoughts on this, or have they been able to reproduce this effect?&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description><pubDate>Wed, 08 Feb 2006 07:47:00 GMT</pubDate><dc:creator>David le Quesne</dc:creator></item><item><title>Table variables with calculated columns in UDFs bug?</title><link>http://www.sqlservercentral.com/Forums/Topic256329-8-1.aspx</link><description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;found what may be a bug in SQL Server 2000 sp4, or maybe I'm just expecting too much of the system!&lt;/P&gt;&lt;P&gt;I have a UDF called ctfn_AMROC which returns a table variable @AMROC containing financial data.&lt;/P&gt;&lt;P&gt;CREATE FUNCTION ctfn_AMROC (@dtAMROCDate DATETIME,                                                   @strClientName VARCHAR(60) = NULL,                                                  @intProjectNumber INTEGER = NULL,                                                  @strProjectManagerID VARCHAR(8) = NULL,                                                  @strCellCode VARCHAR(15) = NULL)RETURNS  @AMROC TABLE (ClientName  varchar (30) NULL ,  JobNumber int NULL ,  ProjectNumber int NULL ,  TotalFee money NULL ,  Claims  money NULL ,  Charges  money NULL,  TotalAMROC  AS ISNULL(TotalFee,0)-ISNULL(Charges,0))AS  BEGIN   ...etc etc...&lt;/P&gt;&lt;P&gt;As you can see, the last column in the table variable, TotalAMROC, is calculated. The function works correctly, returning the correct value of AMROC (Amount Recoverable on Charge) in the TotalAMROC column. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt;However, when I try and edit the function, I have noticed that EM has added a spurious line at the bottom of the function:&lt;/P&gt;&lt;P&gt;(isnull([TotalFee],0) - isnull([Charges],0))&lt;/P&gt;&lt;P&gt;which appears to be a copy of the TotalAMROC calculation.&lt;/P&gt;&lt;P&gt;I get this error message when I try and save the function...&lt;/P&gt;&lt;P&gt;Error 3729: Cannot alter 'ctfn_AMROC' because it is being reference by object 'ctfn_AMROC' &lt;/P&gt;&lt;P&gt;Deleting the offending line at the bottom of the function has no effect. &lt;img src='images/emotions/angry.gif' height='20' width='20' border='0' title='Angry' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt;This only happens if I try and use calculated columns in the table variable. I have to edit the function by copying it into notepad, dropping it and pasting my amendments back in as a new function, which always compiles the first time, but thereafter fails with the above error message.&lt;/P&gt;&lt;P&gt;If I replace the definition of  TotalAMROC with a standard datatype, I do not get the extra line or the error&lt;/P&gt;&lt;P&gt;            TotalAMROC  money NULL)&lt;/P&gt;&lt;P&gt;But then I have to do the calculation in my SQLStatement, which means subtracting two sub-selects.&lt;/P&gt;&lt;P&gt;I cannot find anything in BOL to say you cannot use calculated columns in a table variable. Am I simply expecting too much of SQL Server 2000?&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description><pubDate>Tue, 07 Feb 2006 05:54:00 GMT</pubDate><dc:creator>David le Quesne</dc:creator></item></channel></rss>