September 17, 2010 at 10:06 am
What am I doing worng...? I have several SQL training scripts that use variables this way and they all work. Now all of a sudden, this one fails for no real reason... that I can see. Please help the newbie...
DECLARE @currentBillAt int
SET @currentBillAt = SUM(bill_at) FROM chg_item where batch_id = 9785
PRINT @currentBillAt
It keeps yelling at me about 'FROM'
Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'from'.
All I want is the total vaules of bill_at where the batch = 9785. Bill_at for that batch_id has 20+ rows that need to be added with the SUM().
Thank you
September 17, 2010 at 10:09 am
DECLARE @currentBillAt int
SELECT @currentBillAt = SUM(bill_at) FROM chg_item where batch_id = 9785
PRINT @currentBillAt
September 17, 2010 at 10:10 am
SELECT @currentBillAt = SUM(bill_at) FROM chg_item where batch_id = 9785
Scott Pletcher, SQL Server MVP 2008-2010
September 17, 2010 at 10:11 am
Or, if you really want to use SET:
SET @currentBillAt = (SELECT SUM(bill_at) FROM chg_item where batch_id = 9785 )
Scott Pletcher, SQL Server MVP 2008-2010
September 17, 2010 at 10:15 am
This forum is so good at response time. Thank you...
And on a lighter note, I'm an idiot. Just as my chuckleberry notified me of a new post, I got the sql to work.
DECLARE @currentBillAt
SELECT @currentBillAt
PRINT @currentBillAt
SET changed to SELECT
THANK YOU AGAIN for the dedicated support! 😀
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply