Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
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 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 24th, 2007, 08:05 AM
Authorized User
 
Join Date: Aug 2003
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!

 
Old October 24th, 2007, 08:28 PM
Friend of Wrox
 
Join Date: Oct 2006
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





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





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