| Author |
Topic |
|
dudus
Starting Member
5 Posts |
Posted - 2004-10-17 : 04:49:44
|
| I want to know how can i retrieve several columns into several variables in one select statement.one column: select @workerId = (select workerId from workers)I want to retreive also workername, How can I do that? |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-10-17 : 06:36:02
|
| select @workerId =workerId,@workerName=workerName from workers |
 |
|
|
dudus
Starting Member
5 Posts |
Posted - 2004-10-17 : 08:58:42
|
| thanks,now how can i go over all the records with a loop.what's the syntax? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-10-17 : 09:01:02
|
| Don't use a loop.What are you trying to do exactly? |
 |
|
|
dudus
Starting Member
5 Posts |
Posted - 2004-10-17 : 09:27:59
|
| I want to some kin of a way to calculate values retrieved from the selectfor example:declare @temp bigintselect @payment = payment, @percentage = percentage from workers where workerid >10@temp = @temp + @payment * @percentagethis line: @temp = @temp + @payment * @percentage, happends after the select statement and i wand it to be in the select statement. I hope you get my meaning... |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-10-17 : 09:39:13
|
| You want a running total of the payment/percentage calculation? Or just a total?A regular total:SELECT SUM(Payment * Percentage) FROM workers WHERE workerid>10Running totals are here:http://www.sqlteam.com/item.asp?ItemID=3856 |
 |
|
|
dudus
Starting Member
5 Posts |
Posted - 2004-10-17 : 11:10:02
|
| No i did'nt mean a Sum, my question is a general questions.for example in oracle:for vec in (select id,name from workers)loopx:= vec.id;y:= rec.name;end loop;i want the equivalent code in sql server. |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-10-17 : 11:33:53
|
| Oracle likes to use cursors for everything, cursors are bad in SQL Server and should be avoided as much as possible. See here for more info:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41263Before you reply "I understand, but I'm trying to convert this and I need it quickly..." and so on, understand that this is the BEST advice I can give you, and it WILL save you the most time: DO NOT try to convert Oracle cursors directly to SQL Server. Follow the advice in the above thread, it works. |
 |
|
|
dudus
Starting Member
5 Posts |
Posted - 2004-10-17 : 13:19:34
|
| OK thanks |
 |
|
|
|