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
 Problem Running SQL Query

Author  Topic 

CheesePlant
Starting Member

5 Posts

Posted - 2011-07-05 : 05:12:48
Hello,

We've been playing around with a SQL query but it doesn't display the results.

This is what we have:

SELECT cs2.*, c1.*
FROM CONTSUPP cs
JOIN CONTACT1 c1
ON cs.ACCOUNTNO=c1.ACCOUNTNO
and (c1.zip like '%')
{and (c1.key4 like '%')
OR
join CONTSUPP cs2
ON cs.ACCOUNTNO=cs2.ACCOUNTNO
OR cs2.contact = 'E-mail Address'
and cs2.rectype = 'P'
WHERE cs.RECTYPE = 'P'
AND cs.CONTACT = 'Enquiry'
AND
(cs.address1 like '%')}

---- it seems to die where we have OR. I hope this makes sense (I'm a absolute SQL noob).

Thank you :)

lappin
Posting Yak Master

182 Posts

Posted - 2011-07-05 : 05:42:13
What is the reason for "like '%'" ? The % means "anything", so I can't see what you are gaining - but probably makes the query slower, better to use "is not null" if that is what you mean.

Also using OR statements in WHERE clause see:
http://weblogs.sqlteam.com/jeffs/archive/2007/04/03/Conditional-Joins.aspx

conditional joins are fairly advanced for a SQL noob as you describe yourself. You could possibly use two seperate queries and UNION them.
Go to Top of Page

CheesePlant
Starting Member

5 Posts

Posted - 2011-07-05 : 06:05:00
Hi Lappin,

This SQL is a amalgamation of existing SQL Queries we run in a piece of software called Goldmine. We try patch them together and then its a case of trial and error, that's how noob we are :) I know nothing about SQL.

I'll find out exactly what we are trying to achieve here and get back to you (sorry for not doing this first).

Thank you.

Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 2011-07-05 : 06:52:57
SELECT cs.*, c1.*
FROM CONTSUPP cs
JOIN CONTACT1 c1
ON cs.ACCOUNTNO=c1.ACCOUNTNO
where (c1.zip is not null
and c1.key4 is not null)

OR ( cs.contact = 'E-mail Address'
and cs2.rectype = 'P'
AND cs.RECTYPE = 'P'
AND cs.CONTACT = 'Enquiry'
AND
(cs.address1 is not null)
)
Go to Top of Page
   

- Advertisement -