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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 splitting column values - sql query (July 31)

Author  Topic 

rajsequel
Starting Member

8 Posts

Posted - 2003-07-31 : 02:25:47
Hi,

I want to split a column and get as two in the interface using sql server.

table structure with sample data is :
MyMailBox
=========
MailId MailSubject MailAttachmentSize
====== =========== ==================
100 Hi - from raj 124 k, 220 k
200 Hello anand.. 12 k
300 urgent ...... 45 k, 100 k

from the above i want to get from the third column(i.e MailAttachmentSize) based on the mail id ,

ie. as for MailId 100 - 124k
MailId 100 - 220 k


eg. Select MailAttachmentSize From MyMailBox

want to get as two columns i.e after the "," want to split.





rajesh

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-07-31 : 03:17:15
hi rajesh

how about
select MailId,
case when charindex(',',MailAttachmentSize ) > 0 then substring(MailAttachmentSize, 1, charindex(',',MailAttachmentSize )-1)
else MailAttachmentSize
end,
case when charindex(',',MailAttachmentSize ) > 0 then ltrim(substring(MailAttachmentSize, charindex(',',MailAttachmentSize )+1, Len(MailAttachmentSize)))
else Null
end
from MyMailBox



--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

rajsequel
Starting Member

8 Posts

Posted - 2003-07-31 : 04:00:16
Hi Mr.RRB,

thank u soo much...yr query is working fine...

regds.
rajesh

rajesh
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-07-31 : 09:18:27
quote:
Originally posted by rajsequel
thank u soo much...yr query is working fine...



Thank you so much. Your query is working fine.

Damian
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-07-31 : 19:31:07
Hey Merkin

I know what you mean. So few available posts we've gotta now resort to either writing lymmericks or correcting spelling and grammar....

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -