Solved

limit Db insert on ID

Posted on 2011-02-16
2
262 Views
Last Modified: 2012-05-11
This worked for another table but does not seem to work for this insert statement, basically i don't want to insert into the other table if the SSAN already exists in the table.  What amd I doing wrong.
Insert Personnel.dbo.tblPersonnel (strSSN, strLName, strFName, strMName)
Select	LTRIM(RTRIM(Replace(SSAN, CHAR(160), ''))) SSAN,
		Substring(Name, 1, charindex(' ', name, 1)-1) Last,
		Substring(Name, charindex(' ', name, 1)+1, charindex(' ', name, charindex(' ', Name, 1)+1)-charindex(' ', name, 1)-1) First ,
		Case charindex(' ', Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1) when 0 then '' else 
		Substring(Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1, charindex(' ', Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1)-charindex(' ', name, charindex(' ', Name, 1)+1)-1) End Middle
FROM	[Personnel].[dbo].[tblTemp] where not Exists (Select null from tblPersonnel where SSAN = strSSN)

Open in new window

0
Comment
Question by:kdeutsch
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 34907094
you mean:
Insert Personnel.dbo.tblPersonnel (strSSN, strLName, strFName, strMName)
Select  LTRIM(RTRIM(Replace(SSAN, CHAR(160), ''))) SSAN,
                Substring(Name, 1, charindex(' ', name, 1)-1) Last,
                Substring(Name, charindex(' ', name, 1)+1, charindex(' ', name, charindex(' ', Name, 1)+1)-charindex(' ', name, 1)-1) First ,
                Case charindex(' ', Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1) when 0 then '' else 
                Substring(Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1, charindex(' ', Name, charindex(' ', Name, charindex(' ', Name, 1)+1)+1)-charindex(' ', name, charindex(' ', Name, 1)+1)-1) End Middle
FROM    [Personnel].[dbo].[tblTemp] t
where not Exists (Select null from tblPersonnel p. where LTRIM(RTRIM(Replace(t.SSAN, CHAR(160), ''))) = p.strSSN)

Open in new window

0
 

Author Closing Comment

by:kdeutsch
ID: 34907172
Ok, see what I did wrong, thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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

728 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