February 17, 2012 at 8:03 am
Hi all, i am having trouble using the below statement:
SELECT dqid, DQFlag, DQLinkID INTO DMCDUPES
FROM OrangeDataDQ1
WHERE UPPER([MANAGING COUNTRY] <> 'UK' OR [MANAGING COUNTRY] <> 'BENELUX'
OR [MANAGING COUNTRY] <> 'ITALY'
OR [MANAGING COUNTRY] <> 'SPAIN' OR [MANAGING COUNTRY] <> 'PORTUGAL' OR [MANAGING COUNTRY] <>
'ISRAEL' OR [MANAGING COUNTRY] <> 'GERMANY' OR [MANAGING COUNTRY] <> 'DENMARK'
OR [MANAGING COUNTRY] <> 'NORDIC' OR [MANAGING COUNTRY] <> 'FINLAND'
OR [MANAGING COUNTRY] <> 'ICELAND' OR [MANAGING COUNTRY] <> 'NORWAY'
OR [MANAGING COUNTRY] <> 'POLAND')
AND [Salesforce Account ID] IS NULL
AND DQFlag = 'M'
i am getting an error of:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '<'.
Any help will be much appreciated.
February 17, 2012 at 8:07 am
How about
SELECT
dqid,
DQFlag,
DQLinkID
INTO DMCDUPES
FROM OrangeDataDQ1
WHERE UPPER([MANAGING COUNTRY]) NOT IN (
'UK',
'BENELUX',
'ITALY',
'SPAIN',
'PORTUGAL',
'ISRAEL',
'GERMANY',
'DENMARK',
'NORDIC',
'FINLAND',
'ICELAND',
'NORWAY',
'POLAND'
) AND [Salesforce Account ID] IS NULL
AND DQFlag = 'M'
February 17, 2012 at 8:09 am
Because your WHERE condition are inside UPPER function. By default SQLServer is case insensitive. That should work:
SELECT dqid, DQFlag, DQLinkID INTO DMCDUPES
FROM OrangeDataDQ1
WHERE ([MANAGING COUNTRY] <> 'UK' OR [MANAGING COUNTRY] <> 'BENELUX'
OR [MANAGING COUNTRY] <> 'ITALY'
OR [MANAGING COUNTRY] <> 'SPAIN' OR [MANAGING COUNTRY] <> 'PORTUGAL' OR [MANAGING COUNTRY] <>
'ISRAEL' OR [MANAGING COUNTRY] <> 'GERMANY' OR [MANAGING COUNTRY] <> 'DENMARK'
OR [MANAGING COUNTRY] <> 'NORDIC' OR [MANAGING COUNTRY] <> 'FINLAND'
OR [MANAGING COUNTRY] <> 'ICELAND' OR [MANAGING COUNTRY] <> 'NORWAY'
OR [MANAGING COUNTRY] <> 'POLAND')
AND [Salesforce Account ID] IS NULL
AND DQFlag = 'M'
Consider using NOT IN (...) or have country exclusion table (or temptable) and left join to it. Current query looks like noodles:hehe:
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply