Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
Coalesce on inner queries
Coalesce on inner queries
Rate Topic
Display Mode
Topic Options
Author
Message
Raghunath Garlapati
Raghunath Garlapati
Posted Monday, January 25, 2010 12:00 AM
SSC Rookie
Group: General Forum Members
Last Login: Thursday, February 28, 2013 10:51 PM
Points: 42,
Visits: 133
Hi All,
I have a where condition like
where Fk_Event in
(COALESCE((select fk_event from workscope_event where Fk_user=@userId),Fk_Event)))
actually my requirement is ..if the user is having event it should get only those events other wise all the events.
here the problem is i may get more than one fk_event from inner query , please tell me how can i solve this...Please try to avoid if else statements coz already my query is depending on so many conditions.
/********************************************************
Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
********************************************************/
Post #852853
GilaMonster
GilaMonster
Posted Monday, January 25, 2010 12:07 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 11:08 AM
Points: 37,639,
Visits: 29,893
Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If may also be worth reading
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
and
http://sqlinthewild.co.za/index.php/2009/09/15/multiple-execution-paths/
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #852855
Raghunath Garlapati
Raghunath Garlapati
Posted Monday, January 25, 2010 12:31 AM
SSC Rookie
Group: General Forum Members
Last Login: Thursday, February 28, 2013 10:51 PM
Points: 42,
Visits: 133
Hi,
I have a table workscope_event where i will be having event id and user id mappings,
say for user id --> 1 mapped to events 1,2,3 where i have total 10 events
now i need a query such that if user with Id 1 login to the system it should show only 1,2,3 events but if user with other id logs into the system it shud give all the 10 events.
so as i told from workscope_events i will get mappings of user and event where i need to filter from event table with those events of workwscope_events depending on user login.
/********************************************************
Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
********************************************************/
Post #852864
GilaMonster
GilaMonster
Posted Monday, January 25, 2010 12:38 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 11:08 AM
Points: 37,639,
Visits: 29,893
I'm assuming you didn't read that article. Table definitions, sample data and desired output please.
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #852865
Raghunath Garlapati
Raghunath Garlapati
Posted Monday, January 25, 2010 12:57 AM
SSC Rookie
Group: General Forum Members
Last Login: Thursday, February 28, 2013 10:51 PM
Points: 42,
Visits: 133
k my tables are
package_event (Id int,name nvarchar(50),fk_event int)
workscope_event (fk_user int,fk_event int)
data : Package_Event
Fk_Package
,
Fk_Event
1 1
2 2
3 3
4 4
5 5
6 6
6 1
data : workscope_event
Fk_User
,
Fk_Event
1 1
1 2
1 3
now if the user 1 logs in then the out put should be
Fk_Event
,
Fk_Package
1 1
2 2
3 3
for other users all the events and their packages should come.
/********************************************************
Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
********************************************************/
Post #852868
GilaMonster
GilaMonster
Posted Monday, January 25, 2010 1:06 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 11:08 AM
Points: 37,639,
Visits: 29,893
I'm assuming you didn't read that article.
Ok, so based on that sample data, what do you want the query to return. (actual values please, not a description)
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #852869
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.