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
 General SQL Server Forums
 New to SQL Server Programming
 SET inside of SELECT statement

Author  Topic 

tmaiden
Yak Posting Veteran

86 Posts

Posted - 2007-09-20 : 16:19:30
How can I do this

Select id
set @temp = id
from tblexample

I want to do something, on each row output, with @temp.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-20 : 16:22:07
Select @temp = id
from tblexample


Assuming there is only one Id in the table. If you have multiple rows, you need to restrict the result with proper WHERE condition.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

tmaiden
Yak Posting Veteran

86 Posts

Posted - 2007-09-20 : 16:30:31
there is know way to do it with each row?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-09-20 : 16:38:34
You would have to loop through them using WHILE.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-20 : 16:38:34
What exactly are you trying to do?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

tmaiden
Yak Posting Veteran

86 Posts

Posted - 2007-09-20 : 16:49:36
In my table I have a field called "tracknum" in this field normally is just one number (ex: 2342). Depending upon how many items are being sold (qty) the tracknum field is appened to.
Example: orderid, productid, qty, tracknum
1, 1, 1, '2343'
2, 1, 4, '2344/2345/2346/2347'

I am trying to break these 4 items (orderid = 2) into 4 seperate rows.
2, 1, 1, 2344
2, 1, 1, 2345
2, 1, 1, 2346
2, 1, 1, 2347

I have no clue how to do this. This orginal post is about a function I was trying to use but its not going to work anyway.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-20 : 16:59:38
Look for the split function here: http://weblogs.sqlteam.com/dinakar/archive/2007/03/28/60150.aspx

If you look in the comments I also posted a function that takes a delimited list and returns a table. You can tweak that to get your results.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-09-20 : 18:46:26
If you can, you should really fix that horrible database design.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-21 : 03:03:19
You need normalization
http://www.datamodel.org/NormalizationRules.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -