SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Getting 112 Service code
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Trininole
Yak Posting Veteran

USA
83 Posts

Posted - 09/27/2013 :  14:26:37  Show Profile  Reply with Quote
I am writing a query now where I only want to get participants in the 112 service code only but this query I have is giving me other service codes as well when I have it set to 112. How can I fix this just so i can get this 112 service code only.


declare @bgDte smalldatetime
declare @enDte smalldatetime
declare @rgn char(2)
set @bgDte = '2013-01-01'
set @enDte = '2013-04-30'
set @rgn='05'


select distinct sc.lname lastname,
sc.fname firstname,
sc.usn username,
right(sc.ssn,4)Last4SSN,
svp.servicecode,
s.servicedesc

from ospr_workarea.dbo.static_claimants sc
join
efmextract.dbo.serviceplan svp
on sc.appid=svp.programappid
join
efmextract.dbo.services s
on svp.servicecode=s.servicecode
join ospr_workarea.dbo.svpplx sp
on sc.appid=sp.appid
where 1=1
and svp.actualdate between @bgdte and @endte
and svp.col_lwia=@rgn
and svp.servicecode='112'

Roger DeFour

tkizer
Almighty SQL Goddess

USA
36661 Posts

Posted - 09/27/2013 :  15:15:37  Show Profile  Visit tkizer's Homepage  Reply with Quote
Does the servicecode column appear in ospr_workarea.dbo.static_claimants or ospr_workarea.dbo.svpplx? If so, then you've got "conflicting" data in those.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Trininole
Yak Posting Veteran

USA
83 Posts

Posted - 09/27/2013 :  15:25:30  Show Profile  Reply with Quote
It is in the serviceplan table only.

Roger DeFour
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36661 Posts

Posted - 09/27/2013 :  15:29:06  Show Profile  Visit tkizer's Homepage  Reply with Quote
It's in services too according to the join. What is the data type of servicecode in both services and serviceplan? Though even a data type issue should not have this problem.

Could you show us a data example?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000