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
 Help with a Filter Query

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2007-12-20 : 11:17:29

Hello ,
I am Joining two tables and trying to filter the data based on some conditions.
SELECT SERVICE_TICKET.SERVICE_TICKET_CODE,BuildingAddress.BuildingAddress, BuildingAddress.UserID,SERVICE_TICKET.PROBLEM_REPORTED, SERVICE_TICKET.CONTACT_PERSON, SERVICE_TICKET.STATUS FROM BuildingAddress INNER JOIN SERVICE_TICKET ON BuildingAddress.Customer_Site_Int_ID = SERVICE_TICKET.CUST_SITE_INT_ID WHERE (JoinTable.UserID = @parameter) AND (SERVICE_TICKET.SERVICE_TICKET_CODE LIKE 'HD' + '%')
See in the query at the WHERE clause I am using JoinTable.UserID column actually I know that it is wrong . Could some one tell me how the query should be so that I can get the records from the join which matches the UserID column to a parameter.
Hope that my question is clear.
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-20 : 11:23:30
[code]SELECT SERVICE_TICKET.SERVICE_TICKET_CODE,BuildingAddress.BuildingAddress, BuildingAddress.UserID,SERVICE_TICKET.PROBLEM_REPORTED, SERVICE_TICKET.CONTACT_PERSON, SERVICE_TICKET.STATUS FROM BuildingAddress INNER JOIN SERVICE_TICKET ON BuildingAddress.Customer_Site_Int_ID = SERVICE_TICKET.CUST_SITE_INT_ID WHERE (BuildingAddress.UserID= @parameter) AND (SERVICE_TICKET.SERVICE_TICKET_CODE LIKE 'HD' + '%')[/code]
Go to Top of Page

BendJoe
Posting Yak Master

128 Posts

Posted - 2007-12-20 : 11:32:24
Hi visakh,
I am getting a Result if I use this join with no where condition.
SELECT SERVICE_TICKET.SERVICE_TICKET_CODE,BuildingAddress.BuildingAddress, BuildingAddress.UserID,SERVICE_TICKET.PROBLEM_REPORTED, SERVICE_TICKET.CONTACT_PERSON, SERVICE_TICKET.STATUS FROM BuildingAddress INNER JOIN SERVICE_TICKET ON BuildingAddress.Customer_Site_Int_ID = SERVICE_TICKET.CUST_SITE_INT_ID

Now this result set will have a UserID column. I want to filter this result set by equating the result sets UserID column to the @parameter.

I was using the Query which you gave me for the last few days, but today I noticed that the result is not what I expected. So I started trouble shooting and is still looking for an answer.
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-20 : 11:37:04
you can filter out results by checking returning BuildingAddress.UserID against @Parameter value.
By the way can you remind me the query sent and your expected result?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-20 : 11:53:43
[code]SELECT st.SERVICE_TICKET_CODE,
ba.BuildingAddress,
ba.UserID,
st.PROBLEM_REPORTED,
st.CONTACT_PERSON,
st.STATUS
FROM BuildingAddress AS ba
LEFT JOIN SERVICE_TICKET AS st ON st.CUST_SITE_INT_ID = ba.Customer_Site_Int_ID
AND st.UserID = @Parameter
WHERE st.SERVICE_TICKET_CODE LIKE 'HD%'[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -