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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 complicate combination
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

noamg
Posting Yak Master

Israel
215 Posts

Posted - 06/10/2013 :  05:47:22  Show Profile  Reply with Quote
Dear All,

A store procedure get an input string,
like: ‘( 1 AND ( 2 OR 3 ) OR ( 2 AND 4) ) OR 4 .... ect'

When each number is a table with a column UserID.
So each number represents a list of UserIDs.
AND means using INNER JOIN, OR MEANS using UNION

The SP has to return a select distinct UserID ….
HOW TO SOLVE IT ?


Noam Graizer

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 06/10/2013 :  06:14:23  Show Profile  Reply with Quote
why are you passing like this ‘( 1 AND ( 2 OR 3 ) OR ( 2 AND 4) ) OR 4 .... ect' ?
what is the purpose of SP here? can you explain clearly?

--
Chandu
Go to Top of Page

noamg
Posting Yak Master

Israel
215 Posts

Posted - 06/10/2013 :  06:51:28  Show Profile  Reply with Quote
it is very hard to explain. but this is the core business here.

Noam Graizer
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 06/10/2013 :  07:33:56  Show Profile  Reply with Quote
>>return a select distinct UserID ….
In the first post 1, 2, 3, 4 are UserIds from one table.
Step1: 2 OR 3 --> Both records
Step2: 2 AND 4 --> if both exists then only those two records
Step3: 1 AND AboveRecords (output of above two conditions) --> If 1 is also exists then include those records in output
Step4: Step3 output OR 4 --> Step3 User Ids and 4 to be included in final output...

Is the above result you want?

--
Chandu
Go to Top of Page

noamg
Posting Yak Master

Israel
215 Posts

Posted - 06/10/2013 :  08:01:53  Show Profile  Reply with Quote
no.I need something like this:

select UserID
from T1 T1
inner join (
select UserID from T2
union
select UserID from T3
) as TT
on T1.UserID = TT.UserID
union
....



Noam Graizer
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2165 Posts

Posted - 06/10/2013 :  10:50:22  Show Profile  Reply with Quote
If your parameter is declared as a varchar(whatever), then you will have to parse it so that you can do your where clause correctly.

Can you show us the actual stored proc parameters declaration?








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 06/11/2013 :  11:42:42  Show Profile  Reply with Quote
quote:
Originally posted by noamg

it is very hard to explain. but this is the core business here.

Noam Graizer

If you can't explin it, then how do you expect us to be able to help you?

See the links below on how to ask your question so we can help:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
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.05 seconds. Powered By: Snitz Forums 2000