Solved

Excel reading, comma seperation

Posted on 2007-03-26
1
308 Views
Last Modified: 2010-05-18
I'm reading data from an excel spreadsheet to insert into a database table and have a question.

In one column in Excel, I have "LastName,FirstName". How can I split this out, so when I come to do the insert I can insert LastName and FirstName seperately?
0
Comment
Question by:PeterErhard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 18796317
It depends, if you are using DTS than it is as simple as using the VBScript Split() function and mapping them into your column names. If you only want to use T-SQL than you will have to do something like this:

CASE
           WHEN CHARINDEX(',', YourColumnName) > 0 THEN LEFT(YourColumnName, CHARINDEX(',', YourColumnName) - 1)
           ELSE YourColumnName
END LastName,
CASE
           WHEN CHARINDEX(',', YourColumnName) > 0 THEN SUBSTRING(YourColumnName, CHARINDEX(',', YourColumnName) + 1, 100)
           ELSE Null
END FirstName,
...
From YourStagingTable
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question