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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 -1*value

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 #temptable
select 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 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.5 out!
Go to Top of Page

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.
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-03-30 : 11:01:40
And I get an error.

Incorrect syntax near the keyword 'select'
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -