Do you have any good concise tutorials about variable syntax? This is part of a sproc:
Set @sql = 'Set ' + @calc + '= SUM(datalength(' + @column_name + '))/2 from ' + @table_name
exec (@sql)
And it doesn’t work – I get an Error converting data type varchar to numeric. Here is the simulated example:
DECLARE @calc numeric(18,2)
DECLARE @sql nvarchar(1500), @column_name nvarchar(50), @table_name nvarchar(50)
Set @column_name = 'EID'
Set @table_name = 'CTY_SUPPORTED'
Set @sql = 'Select @calc = SUM(datalength(' + @column_name + '))/2 from ' + @table_name
exec (@sql)
print @calc
I’m interested in attributing to variable @calc the following value: SUM(datalength(column_x))/2 from table_x
Also if you know syntax lessons (preferably not encyclopedias) – many thanks and gooday!
1 Answer