Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 1st, 2009, 08:09 PM
Authorized User
 
Join Date: Dec 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendar
Default Comma Separated One row into Multiple columns

CREATETABLE #Locations
(Name1 VARCHAR(100))
INSERTINTO #Locations values('Scott,M,36')
INSERTINTO #Locations values('Eric,M, 24')

I need Output three columns like

Name Group Age
Scott M 36
Eric M 24

Thanks in advance
 
Old October 6th, 2009, 08:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

SELECT REPLACE(Name1 , ',', ' ')
__________________
Always,
Hovik Melkomian.
 
Old October 7th, 2009, 02:24 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Didn't you ask nearly identically this same question in another post and/or another forum????

If you didn't then your clone did.

Code:
CREATETABLE #Locations
(
  Name VARCHAR(100),
  Group VARCHAR(20),
  Age INT 
)
INSERTINTO #Locations values('Scott','M',36)
INSERTINTO #Locations values('Eric','M', 24)
...
If you WANT three fields, then CREATE three fields. The DB can't magically guess that you want your single value to suddenly become three. Especially when you created the table to only have one field.
 
Old October 7th, 2009, 02:26 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yes! You did!

Why didn't you READ the answer I gave you yesterday????

SQL Server 2008 Query (comma separated)
 
Old October 9th, 2009, 01:52 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

Another Method is using MS Access:
  • Load .txt file into MS Access;
  • Folloow the import Wizard, which will show you yur imported file after you respond to how the file is delimited. In your case, you would select, "comma delimited";
  • The file is then displayed. You will have the option to adjust the columns and name them (columns). Also the Wizard will ask if you wanted to add the primary key;
  • Save the file in a table;
  • The End;
Next is to export your table using the MS XL format;
Give the output file a name with the .xls extention;
File is created;
Locate file .xls and upload file into your SQL database;

Just another way of getting what you need.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Comma Separated values aldwinenriquez SQL Server 2005 3 June 1st, 2007 08:52 PM
comma separated list MunishBhatia SQL Server 2000 11 March 21st, 2007 03:56 PM
Comma Separated Column Value thru T-SQL subhendude SQL Server 2000 2 December 12th, 2006 01:42 PM
comma separated list of attributes rjonk XSLT 3 September 27th, 2006 11:52 AM
Select from Comma Separated Values sasidhar79 SQL Server 2000 2 March 28th, 2005 06:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.