473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL Server query connecting through SAS

I am using SAS with SQL Server and I have a query that will just not run. It does not like something about my subquery.

Everything is correct but when It gets to this it errors out.

where (memID,fst_srvc_dt) in
(select distinct
memID,
fst_srvc_dt
from table
where memid>0
and
insured='FI'
and
lob in ('CO', 'SF')

If I take out the where () in and replace it with
where exists
(select distinct

it runs.

but the subquery has to return only those that are
where (memid_fst_srvc_dt) in

I am just not sure how to make it work.
Feb 6 '12 #1
7 2553
Rabbit
12,516 Expert Mod 8TB
You can't do this (memID,fst_srvc_dt). Instead, turn your where clause subquery into an inner join subquery and join on those two fields.
Feb 6 '12 #2
@Rabbit


I am not sure how to do that on the same table. There is only 1 table and I only know how to do joins if I am joining another table to it and then do the whole on this field and that field. Here is my entire query from the start:


proc sql;
connect to odbc(database=oxford);
create table reminder.clms_mrg as
select * from connection to odbc
(select distinct
member_id,
year(earliest_service_date_key) as year,
earliest_service_date_key as fst_srvc_dt,
self_fully_insured as finc_arng_cd,
market as state,
CASE WHEN procedure_code IN ('93510','93511','93524','93526','93508','93452',' 93453','93454','93455','93456','93457',
'93458','93459','93460','93461') THEN 1 END AS CATH,
case when procedure_code in ('33206','33207','33208','33212','33213','33214',' 33225','33240','33249') then 1 end as EP,
case when procedure_code in ('92982','92983','92984','92980','92981','G0290',' G0291','92995','92996') then 1 end as PCI,
sum(allowed_amount) as allw_amt
from oxford2009claims
where (member_id,earliest_service_date_key) in
(select distinct
member_id,
earliest_service_date_key
from oxford2009claims
where
member_id>0
and
procedure_code IN ('93510','93511','93524','93526','93508','93452',' 93453','93454','93455','93456','93457',
'93458','93459','93460','93461','92982','92983','9 2984','92980','92981','G0290','G0291','92995','929 96',
'33206','33207','33208','33212','33213','33214','3 3225','33240','33249')
and
self_fully_insured ='FI'
and
lob_code !='MC')and self_fully_insured = 'FI'
group by member_id,earliest_service_date_key,self_fully_ins ured,procedure_code,market)
order by member_id,fst_srvc_dt,finc_arng_cd,state;
disconnect from odbc;
quit;


Now I cannot do the where () in statement and I am not sure about this inner join to the same table which is called oxford2009claims.
Feb 6 '12 #3
Rabbit
12,516 Expert Mod 8TB
That's what you're trying to do? Why do you need a subquery? Just include the where conditions of the subquery in the main query.
Feb 6 '12 #4
I cannot because the procedure codes in the main query are different than the ones in the subquery
Feb 6 '12 #5
Rabbit
12,516 Expert Mod 8TB
The procedure codes look the same to me.
Feb 6 '12 #6
@Rabbit
Well the way my boss has her query set up that connects to a ton of differing tables on another server, she pulls all the procedure codes for a group of members. Then she does the where()in statement to take only those members with the results above to pull only those that have claims in the procedure codes that are in the where()in statement. I am not sure if she is doing this because she has to connect to like 12 differing tables or what? So maybe I can get away with not doing a where(in) or subquery. Not sure. Will see what the results are.
Feb 6 '12 #7
Rabbit
12,516 Expert Mod 8TB
Well, as far as I can tell, the procedure codes in the subquery are the same as the procedures in the case statements. So if those are the only procedure codes needed, then the subquery is unnecessary.
Feb 6 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roberto :- | last post by:
Hi, I'm getting errors when trying to run a query over linked servers that works fine on a single server. The error text that comes up in QA is as follows; Server: Msg 8180, Level 16, State...
2
by: vidya | last post by:
Hi, I wrote a stored procdure in SQL Server which calculates some metrics. This procedure always returns only one row with 11 columns of integer values. I ran it in SQL Server Query Analyzer...
2
by: Jorge Varona | last post by:
Greetings, I am having a difficult time trying to get my index server query to work. Here's the code: // create a connection object and command object, to connect the Index Server ...
3
by: s_wadhwa | last post by:
Hi, I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp application with SQL Server as Backend. I'm having trouble converting Access Query into SQL Query. The Query is...
1
by: wintonsl | last post by:
Would anyone know how to convert this Access Query to SQL Server Query? Format(((+++)/(IIf(>0,1,0)+IIf(>0,1,0)+IIf(>0,1,0)+IIf(>0,1,0))),"Standard") What this query is doing in Access is...
4
by: winniewang | last post by:
Hi everyone, Who can help me to translate the SQL Server query to DB2 query? The query were shown as below: CAST( CONVERT( CHAR(2), MonthNumberOfYear) + '/ ' + '1/' + CalendarYear AS...
1
by: wquatan | last post by:
I have a problem with an Access Update-Query (made in the designer) for a SQL-server Table. The Query consists out of the Table to be updated, and a joined "Select" subquery to provide the...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
0
by: mina | last post by:
My application which is written in vb.net 2005 uses sql server 2005 express as a database, this application is multi-user. So i am used 3 xp machine to install my application i can say...
3
by: Kunal Desale | last post by:
Hello, I am migrating access queries to SQL Server 2005 Queries. My Access Query Is: SELECT qtrade.intordreftrim AS Expr1, qtrade.extordreftrim AS Expr2, qtrade.intinvreftrim AS Expr3,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.