wppiexperts
asked on
Return a single value to a variable
I'm trying to get a single value (row count) and write it to a text file.
I'm trying to get the row count value into the variable @spcount and then output it using this code:
set @cmd = 'master..xp_cmdshell "echo Record Count:' + @spcount + '>> d:\file.txt"'
exec (@cmd)
Unfortunately, I can't seem to pass the row count value via the @spcount variable to the file, I always get a value of 0
the code I'm trying to use to assign the value is:
exec @spcount=xdb..sp_executesq l N'select count(*) from xtable'
another variation of that line:
exec xdb..sp_executesql N'select count(*) from xtable'
run by themselves, I get the correct output, but when trying to embed the results into the code above, again I get 0
any suggestions?
I'm trying to get the row count value into the variable @spcount and then output it using this code:
set @cmd = 'master..xp_cmdshell "echo Record Count:' + @spcount + '>> d:\file.txt"'
exec (@cmd)
Unfortunately, I can't seem to pass the row count value via the @spcount variable to the file, I always get a value of 0
the code I'm trying to use to assign the value is:
exec @spcount=xdb..sp_executesq
another variation of that line:
exec xdb..sp_executesql N'select count(*) from xtable'
run by themselves, I get the correct output, but when trying to embed the results into the code above, again I get 0
any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select @spcount=count(*) from xtable