Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Select Statement

Status
Not open for further replies.

sqlserverbest

Programmer
Jan 16, 2003
8
0
0
US
How do print the value of variable @totsum


declare @totsum money, @sql varchar(1000)
set @sql = 'select @totsum = sum(price) from product'
execute(@sql)

print str(@totsum,15,2)

I am getting the message as @totsum not declared.

Your help is appreciated.
 
Have a look at tbroadbents response to thread183-449585 SQL working backwards


cjw
 
That me again!!!

I tried this code making it much simpler and it said I much declare @rowcount variable when it is already declared.

DECLARE @sql varchar(1000), @rowccount int
SET @sql = 'Select @rc=count(*) From ttg_position_stg'
EXECUTE sp_executesql @sql, N'@rc int output', @rc=@rowcount output

Help is appreciated
 
Try this simpler form:

declare @totsum money
select @totsum = sum(price) from product
print @totsum

Format as you please.


Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top