Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 24th, 2007, 08:05 AM
Authorized User
 
Join Date: Aug 2003
Location: Pittsburgh, PA, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert into....select problem

Hello all...
First off, I'm new to sql server.

I'm trying to make a stored procedure that queries records from one table and needs to insert them into another. But if there is a matching record already there, append that new information. Then write new records in the table. I receive an error message complaining about the & sign.


My code is below:
----------------------------
INSERT INTO [Customer_Export] ( PREVIOUS_ID, [BKN00-KTOKD], [BKNA1-NAME1], [BKN00-VKORG_P],
 [BKN00-VTWEG_P], [BKN00-SPART_P], [BKNVP-PARVW], [BKNVP-KTONR], [BKNVP-DEFPA] ) &_


SELECT dbo.[T_Customer Master Data_Partner].PREVIOUS_ID,
        dbo.[T_Customer Master Data_Partner].[BKN00-KTOKD],
        dbo.[T_Customer Master Data_Partner].[BKNA1-NAME1],
        dbo.[T_Customer Master Data_Partner].[BKN00-VKORG_P],
        dbo.[T_Customer Master Data_Partner].[BKN00-VTWEG_P],
        dbo.[T_Customer Master Data_Partner].[BKN00-SPART_P],
        dbo.[T_Customer Master Data_Partner].[BKNVP-PARVW],
        dbo.[T_Customer Master Data_Partner].[BKNVP-KTONR],
        dbo.[T_Customer Master Data_Partner].[BKNVP-DEFPA] &_
FROM dbo.[T_Customer Master Data_Header] INNER JOIN dbo.[T_Customer Master Data_Partner]
ON (dbo.[T_Customer Master Data_Header].[BKN00-KTOKD] = dbo.[T_Customer Master Data_Partner].[BKN00-KTOKD])
AND (dbo.[T_Customer Master Data_Header].PREVIOUS_ID = dbo.[T_Customer Master Data_Partner].PREVIOUS_ID)
---------------------------------------------------------------
This is my error message:
Msg 102, Level 15, State 1, Procedure Export_Customer_Z001_Partner, Line 33
Incorrect syntax near '&'.

-------------------------------------------------------------
Thanks!

Reply With Quote
  #2 (permalink)  
Old October 24th, 2007, 08:28 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

What's the "&_" for? Don't need line continuations in SQL Server.

Also, if you want to simplify your code a bit, consider the following...

SELECT Cst.CustomerID, Cst.CompanyName, Cst.ContactName,
       Ord.ShippedDate, Ord.Freight
FROM Northwind.dbo.Orders AS Ord
  JOIN
     Northwind.dbo.Customers AS Cst
  ON (Cst.CustomerID = Ord.CustomerID)

"Cst" and "Ord" are called "Table Aliases" and allow for the shorthand shown in the SELECT list and join conditions. You can even join two copies of the same table to itself using table aliases.

--Jeff Moden
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT INTO with parameterized values and SELECT elygp SQL Server 2000 1 September 6th, 2007 04:48 AM
A select and then an insert in a stored proc smacks SQL Server 2005 3 July 21st, 2007 07:31 PM
SELECT/ORDER/INSERT Stuart Stalker SQL Server DTS 1 July 24th, 2005 01:00 AM
problem with insert, on select data doesn't show pascalgeuze ADO.NET 1 April 24th, 2004 01:50 AM



All times are GMT -4. The time now is 03:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.