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 |
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-03-30 : 10:44:07
|
Hello,Could you please look at the query?What's wrong?declare @qry2 varchar(8000)declare @qry varchar(8000)select @qry2='(select sum(AMT) from table1)*(-1) +(select sum(AMT) from table2)'select @qry='insert #temptableselect total = '+@qry2+'' If I remove *(-1), the query runs well, but I need it.Thanks for any help. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2009-03-30 : 10:46:28
|
| try:select @qry2='select ((select sum(AMT) from table1)*(-1) +(select sum(AMT) from table2)) as C'___________________________________________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.5 out! |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-03-30 : 10:58:44
|
| I defined total in the table #temptable but you used C.It is not working. |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-03-30 : 11:01:40
|
| And I get an error.Incorrect syntax near the keyword 'select' |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-03-30 : 13:20:43
|
| Would this work?select @qry2='(select sum(AMT)*(-1) from table1) +(select sum(AMT) from table2)Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
|
|
|