Author |
Topic |
eurob
Posting Yak Master
100 Posts |
Posted - 2005-08-31 : 12:38:57
|
declare @a intselect clientid,@a from mytableI get the error : "A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations."How can be worked around this issue ?Thanksrobert |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-08-31 : 14:30:20
|
SELECT @a = ClientID FROM MyTable |
|
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-08-31 : 14:59:45
|
sorry, i forgot somethingdeclare @a intselect clientid,@a = sum(items) from mytableI get the error : "A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations."robert |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-08-31 : 16:01:55
|
Gotta use two steps. It makes sense.SELECT @a = sum(items) from MyTableSELECT ClientID FROM MyTableTake a look and think about why doing both in a single step is a conflict. |
|
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-09-01 : 07:53:55
|
But I need the sum grouped by client, so I need to have it in one select.robert |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-01 : 08:43:56
|
Try thisSELECT @a = sum(items) from MyTable where Clienid=someIdMadhivananFailing to plan is Planning to fail |
|
|
anandc
Starting Member
20 Posts |
Posted - 2005-09-01 : 08:44:35
|
You may use the query like this...SELECT clientid, SUM(items) as A FROM mytable- Anand |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-01 : 08:50:53
|
quote: Originally posted by anandc You may use the query like this...SELECT clientid, SUM(items) as A FROM mytable- Anand
That should beSELECT clientid, SUM(items) as A FROM mytable group by ClientidMadhivananFailing to plan is Planning to fail |
|
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-09-01 : 10:04:18
|
quote: SELECT @a = sum(items) from MyTable where Clientid=someId
This does not work, I get the same error msg as I got with my first post. I guess I would have to work with a temp table ? I need to use variables because within the select I want to add and subtract later on.robert |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-01 : 10:11:25
|
Can you post some sample data and the result you want?MadhivananFailing to plan is Planning to fail |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-01 : 10:57:30
|
What's the problem you are wanting to solve?When I look at your example:declare @a intselect clientid,@a = sum(items) from mytable it looks like you are trying to output "clientid", but "keep" the @a total for some further processing - and at that point I am sure I have misunderstood your problem!!Kristen |
|
|
ke.neelima
Starting Member
6 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
shijobaby
Starting Member
44 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|