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
 help required

Author  Topic 

mym
Starting Member

4 Posts

Posted - 2010-11-01 : 02:52:36
dear guys i am new sql, i have a table which contains a single column whose data is like 1,2,3,4,5 now i want to disply these all in seperate column through query how can i do this???????

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-11-01 : 03:34:19
Use the split function -
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

mym
Starting Member

4 Posts

Posted - 2010-11-01 : 03:35:47
guys i have +ve and -ve values in one column i want to to display both in seperate column through query kindly help me in this regards if any one know thx waiting for replies.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-11-01 : 03:45:39
Please show some sample data as in your previous post there is not any -ve value and there are more than two values.
Is there only two values in one column or might be more that two values ?

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

mym
Starting Member

4 Posts

Posted - 2010-11-01 : 04:07:39
actually i have two columns
emp_id , emp_name
1 , jog
2 , bang
3 , witz
4 , xlmz
5 , john

now i wnat to disly the employees whose name start with 'j' in one column and whose name start with 'w' in other column, so how can i do this?
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-11-01 : 04:20:34
I think everytime you are asking different question without answering posts.

anyways
Reply of your last post -

What if count of j and w is not same ?
In this case if you want to show NULL then use this -


DECLARE @Table AS TABLE ( emp_id int, emp_name VARCHAR(30) )
INSERT INTO @Table
SELECT 1 , 'jog' UNION ALL
SELECT 2 , 'bang' UNION ALL
SELECT 3 , 'witz' UNION ALL
SELECT 4 , 'xlmz' UNION ALL
SELECT 5 , 'john'

SELECT CASE WHEN Emp_Name LIKE 'j%' THEN Emp_Name ELSE NULL END 'J'
,CASE WHEN Emp_Name LIKE 'w%' THEN Emp_Name ELSE NULL END 'W'
FROM @Table



Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

mym
Starting Member

4 Posts

Posted - 2010-11-01 : 04:51:36
thanks dear it is working and i need exactly this thanks alot a little quesstion is that if there are some null values in emp_name and i dont want to disply them how can i do this.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-11-01 : 05:11:00
Its simple just put the where clause in above query -
WHERE Emp_Name IS NOT NULL

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page
   

- Advertisement -