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
 Getting 112 Service code

Author  Topic 

Trininole
Yak Posting Veteran

83 Posts

Posted - 2013-09-27 : 14:26:37
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

38200 Posts

Posted - 2013-09-27 : 15:15:37
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

83 Posts

Posted - 2013-09-27 : 15:25:30
It is in the serviceplan table only.

Roger DeFour
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-09-27 : 15:29:06
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
   

- Advertisement -