Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-09-20 : 07:13:21
|
| Mr.Tran writes "DECLARE @sT nvarchar(255)SELECT @sT = ('SELECT SUM(sotien) AS tongtien FROM ' + @vw + ' WHERE idnhanvien=' + @fMaNV + ' AND thangnhan=' + @i) SET @vThang = EXEC(@sT)why it don't working ??? Please help me !" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-09-20 : 07:43:11
|
quote: SET @vThang = EXEC(@sT)
You can't do it that way to get Sum(sotien) assigned to local variable. You will have to use sp_executesql for this:Declare @sql nvarcharSet @sql = N'SELECT @vThang = SUM(sotien) AS tongtien FROM ' + @vw + ' WHERE idnhanvien=' + @fMaNV + ' AND thangnhan=' + @iexec sp_executesql @sql, N'@vThang int output', @vThang Output Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-20 : 07:48:27
|
Make use of sp_excutesql DECLARE @sT nvarchar(255), @Sum floatSelect @sT 'SELECT @Sum = SUM(sotien) AS tongtien FROM ' + @vw + ' WHERE idnhanvien=' + @fMaNV + ' AND thangnhan=' + @isp_executesql N @sT N'@Sum float output', N' @Sum = @Sum output Select @Sum Chirag |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-20 : 07:49:33
|
Chirag |
 |
|
|
|
|
|