Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 not equal to

Author  Topic 

rob41
Yak Posting Veteran

67 Posts

Posted - 2010-11-19 : 08:49:07
I'm trying to get this query to only load new records that are not the same as the records that previously exist in the table

WHERE [ChargeAmts].[Load Id] <> [Estimated].[Load Id]
AND [ChargeAmts].[Ship Id] <> [Estimated].[Ship Id]
AND [ChargeAmts].[cs Code] <> [Estimated].[cs Code]

I'm getting this error

Msg 156, Level 15, State 1, Line 22
Incorrect syntax near the keyword 'WHERE'.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-19 : 08:52:37
Can you post complete select statement ?
Go to Top of Page

rob41
Yak Posting Veteran

67 Posts

Posted - 2010-11-19 : 08:58:12
INSERT INTO [ChargeAmts]
([Load Id],
[Ship Id],
[cs Code],
[Est AP Amt],
[Est AR Amt])
SELECT [Estimated].[Load Id] AS [Load Id],
[Estimated].[Shipment Id] AS [Ship Id],
[Estimated].[cs Code] AS [cs Code],
SUM([Estimated].[AP Est Acs Amt]) AS [AP Est Acs Amt],
SUM([Estimated].[AR Est Acs Amt]) AS [AR Est Acs Amt]
FROM [Shipments]
INNER JOIN [Estimated]
ON ([Shipments].[Ship Id] =
[Estimated].[Ship Id] )
AND ( [Shipments].[Load Id] =
[Estimated].[Load Id] )
GROUP BY [Estimated].[Load Id],
[Estimated].[Ship Id],
[Estimated].[cs Code]
WHERE [ChargeAmts].[Load Id] <> [Estimated].[Load Id]
AND [ChargeAmts].[Ship Id] <> [Estimated].[Ship Id]
AND [ChargeAmts].[cs Code] <> [Estimated].[cs Code]
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-11-19 : 09:06:38
quote:
Originally posted by rob41

INSERT INTO [ChargeAmts]
([Load Id],
[Ship Id],
[cs Code],
[Est AP Amt],
[Est AR Amt])
SELECT [Estimated].[Load Id] AS [Load Id],
[Estimated].[Shipment Id] AS [Ship Id],
[Estimated].[cs Code] AS [cs Code],
SUM([Estimated].[AP Est Acs Amt]) AS [AP Est Acs Amt],
SUM([Estimated].[AR Est Acs Amt]) AS [AR Est Acs Amt]
FROM [Shipments]
INNER JOIN [Estimated]
ON ([Shipments].[Ship Id] =
[Estimated].[Ship Id] )
AND ( [Shipments].[Load Id] =
[Estimated].[Load Id] )
WHERE [ChargeAmts].[Load Id] <> [Estimated].[Load Id]
AND [ChargeAmts].[Ship Id] <> [Estimated].[Ship Id]
AND [ChargeAmts].[cs Code] <> [Estimated].[cs Code]
GROUP BY [Estimated].[Load Id],
[Estimated].[Shipment Id],
[Estimated].[cs Code]



Try in the above way
Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

rob41
Yak Posting Veteran

67 Posts

Posted - 2010-11-19 : 09:29:18
thanks it worked :)
Go to Top of Page
   

- Advertisement -