If one query returns any result then the result from other query should be eliminated..


I want to create a query which returns allowed reports for the user.

There are two different queries which returns the allowed reports. One returns the reports according to user and other reutrns reports according to the role of user.

e.g.Select ReportID from UserReports and  select ReportID from RoleReports (in original scenario both queries are quite complex and large)

Requirement is if the first query returns any row then the result of the from the second query should be ignored.

IF(Select ReportID from UserReports > 0)


Select ReportID from UserReports




select ReportID from RoleReports


This is the way of doing this kind of things. But the problem is that i donot want to put the query in IF statement as it is quite resource killer query. In this manner it will run twice.

Is there any other better way of doing it?




People can just tell you what to do... Don't expect them to do it for you
7/22/2008 1:55:35 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 14

You can just write a single query to get the information that you need out. Or wrap it in a stored procedure.

7/22/2008 1:58:58 PM

In a stored procedure, check the @@RowCount global variable.

Set NoCountOn

Select ReportId From UserReports

If @@RowCount = 0


    Select ReportID from RoleReports



7/22/2008 2:23:31 PM

kool it worked... i really liked it..thanx

People can just tell you what to do... Don't expect them to do it for you
7/23/2008 10:28:01 AM

Similar Artilces:

Combine SQL query result with XML query result
Hi all, Hopefully someone can help me with this: I know how to setup and run a query on an SQL db and I can probably work out how to query an XML file, but how do I take the results of each and combine them into one collection (i'm presuming a dataset)? Once i've created the combined collection, i'd want to order it by some universal identifier present in both datasources e.g. product ID. It's worth pointing out that the XML file would not be in the same format/use the same field names (or number of fields) as the SQL query, so I guess I might need to bind my query resu...

Return result from one query as a column in other query
I'm having a bit of a trouble explaining what I'm trying to do here. I have 3 "source" tables and a "connecting" table that I'm going to use tblContacts - with contactID, ContactName etc tblGroups - with GroupID, GroupName tblSubGroups - with SubGroupID, GroupID and SubGroupName (groupID is the ID for the parent Group from tblGroups) They are related in a table called tblContactsGroupConnection - with ContactID, GroupID and SubGroupID One contact can be related to many subgroups. What I want is a list of all contacts, with their IDs, names and wh...

Novice DBA looking for Advice on Querying the result of a query of a results of a query of a....
Many thanks in advance! Here's an example of what I'm working on.  Let's say I have a row of data that is returned in a query.  The columns are First, Middle, and last.  We'll say the values in each column, respectively, are 1, 2, and 3. So I run my first query, something akin to SELECT MIDDLE WHERE MIDDLE = 2.  And we get that row.  Excellent. What I'm trying to do, is after that statement is executed, run another one on the webpage that looks like SELECT LAST WHERE LAST = [the value that was returned in the previous statment]. And the k...

Search query returns XML results. How do I get the results back to the page that submitted the query or a new page.
Hello,I have a search page with a text box and button. When I search for a keyword, my page sends parameters to a search appliance that returns XML results. How can I get the results back to my search page or some other page on my site and not the search appliance. I know I need xlst to transform the XML results but, how do I get the results back on my site instead of the appliance on by just entering a keyword and clicking on the search button. Thanks for any help! I'm assuming that you are doing a direct form based post to the search appliance which is a service taking a keyword and retu...

AutoComplete results not the same at sql query results
For some reason my AutoComplete web service is not return the same data set as when I run the query manually. For example, here is my Oracle query and the results: p_value = 'HOME DEPO'; SELECT TRIM(spropertyname) spropertynameFROM usaa_acqpropertiesWHERE spropertynamecaps LIKE (p_value || '%') Returns:Home DepotHome Depot (Winchester, VA)Home Depot - Colma Using the AutoComplete I only get one entry:Home Deposition Sciences, Inc.Here is my webservice code: [WebMethod]public string[] AutoCompletePropName(string prefixText, int count){string prefixTextUpper = prefixText.T...

How To Combine 2 SQL Query Results Into One In Order To Bind to a Gridview Datasource?
Hi, Scenario: In code behind (.cs), I have to perform two seperate sql queries. For the simplicity, First I need to select the CustomerName from TableA. then another query to select CustomerPhone from TableB. Note that there IS NO join between these two tables. How can I combine these two resullts so that I can bind it to a single gridview datasource? Any suggestion for a simple solution.. ? Do your tables have only one column?  Iterate through tableB and copy all rows to tableA...  http://support.microsoft.com/kb/305346 It could also be done at...

Querying a Queried result...
Hi, is there such a thing as querying a queried result? Example, query 1 produces Result A. Result A's table is stored 'somewhere' to be queried by query 2 which produces Result B If there is, could you kindly direct me to a website with the appropiate article on this topic? Thanks, -Gabian- Yes there is, querying a View is querying a query rewrite. Send me an email the address is in my profile I will send you a Views tutorial I wrote a while back and run a search for query results from View in your BOL(books online) for code samples. Hope this helps. Kind regards, ...

Results of One Query Used In A Second Query
I don't know the correct approach to this problem. Nested Queries perhaps? I have users enter stock symbols into a textbox. The symbols are then written in a table that has 3 columns named UserID, Portfolio_Name and Portfolio_Symbols. In order to look the symbols up (Portfolio_Symbols), I search by UserID and Portfolio_Name; this returns a string consisting of the symbols. What I need, however are the results of (another) query based on these symbols(Portfolio_Symbols)--the result would be various pieces of data for each company (symbol)being returned to a dataset that will be read...

sqlreader returning false even though Sql query Analyzer returns a result
Hi, I have this problem with my sqlreader, my sql returns a result in analyzer but when I use the same statement in my sqlreader its not returning any results ie returns false.   Can anyone help?   many thanks Hi,1. Are you sure it's EXACTLY the same SQL statement executing on both?2. Are you sure they are both pointing to the same database?If so, post the code and we'll take a look. ...

can i do an sql query then use the result of that in another query...
for instance i need to find value of storyId from one table then make sure i do not pull that record from another table. is this possible With SQL you can do something like this: select * from TableB where StoryIdValue not in (select StoryIdValue from TableA) This is just 1 of many possible solutions. ChrisDont forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. Yes this is possible. This is what is called a "Nested Query" in SQL. ...

Returning only 3 results from a sql query.
Hi, I would like to know how to return only 3 results from a sql query. I have a gridview that displays a list of search results. If the user selects one the results they are transferred to a new page. On the new page I would like to display another gridview returning only 3 results from the same search but the only the results next to the selected result. For example if the 21st result was chosen on the next page a gridview would display the 20th and 22nd result. Kind of like "SELECT TOP 3 * FROM tablename" but "SELECT 20 - 22 * t...

Return the results of a select query in a column of another select query.
Not sure if this is possible, but maybe. I have a table that contains a bunch of logs. I'm doing something like SELECT * FROM LOGS. The primary key in this table is LogID. I have another table that contains error messages. Each LogID could have multiple error messages associated with it. To get the error messages. When I perform my first select query listed above, I would like one of the columns to be populated with ALL the error messages for that particular LogID (SELECT * FROM ERRORS WHERE LogID = MyLogID). Any thoughts as to how I could accomplish such a daring feat?http://w...

Easy SQL question. How to display query results in Query Analyzer
When I run the following query from Query Analyzer in SQL Serer 2005, I get a message back that says. Command(s) completed successfully. What I really need it to do is to display the results of the query. Does anyone know how to do this? declare     @SniierId as   uniqueidentifierset @SniierId = '85555560-AD5D-430C-9B97-FB0AC3C7DA1F'declare    @SniierAlias  as nvarchar(50)declare    @AlwaysShowEditButton  as bitdeclare     @SniierName  as  nvarchar (128)/* Check access for Snii...

VB .NET Dataset SQL query results
Hi, I'm hoping someone can shed some light on how I can address variables returned to a dataset via a stored procedure.I've coded an AJAX Autocomplete control but due to the restriction of the control (only being able to return one value) I now need to use the returned value to search my DB.  The stored procedure used for the Autocomplete returns the key information (and the description).  I'm assuming the key info is stored within the dataset. So my question is, how do I read the key information into a variable for use elsewhere?Stored proc Select Statement; SELECT SU...

Web resources about - If one query returns any result then the result from other query should be eliminated.. - asp.net.sql-datasource

Today, The Plain Dealer eliminated the... - SaveThePlainDealer - Facebook
Today, The Plain Dealer eliminated the jobs of approximately 50 journalists whose dedication produced one of the country’s best newspapers. The ...

It's Time We Eliminated the Corporate Income Tax - Robert Reich
It's time we eliminated the corporate income tax and made up the shortfall by increasing capital gains taxes. Here's the logic: First, the corporate ...

Eliminated House Rules duo Maddie and Lloyd strengthen relationship as Candy and Ryan split
They say absence makes the heart grow fonder and, according to House Rules pair Maddie and Lloyd, so does appearing on a renovation series.

New Zealand breeze into Dubai Sevens quarter-finals, Australia eliminated
Favourites New Zealand coasted into the quarter-finals of the Dubai Rugby Sevens on Friday, as they looked to follow up on their win in the first ...

The Bachelorette Australia 2015: Have the eliminated contestants found love yet? - HeraldSun Search Search ...
SINCE THE Bachelorette finale aired on Thursday night, all eyes have been on Sam Frost and her chosen beau, Sasha Mielczarek.

‘Dancing With The Stars’ Season 21 Week 9: Alexa Pena Vega and Mark Ballas eliminated [WATCH VIDEO]
Tamar Braxton was taken ill and shifted to the emergency room, but fortunately was back for her team dance.

The Bachelorette Australia 2015: Have the eliminated contestants found love yet?
SINCE THE Bachelorette finale aired on Thursday night, all eyes have been on Sam Frost and her chosen beau, Sasha Mielczarek.

MasterChef finalist Sara Oteri of Perth eliminated - PerthNow Search Search
PERTH MasterChef finalist Sara Oteri has been eliminated from the hit show’s finals week. But there’s still one more WA contender.

Patient restraint should be 'eliminated'
Sky News is Australia's leader in 24-hour news.

Natalia Semenova eliminated from discus after freak accident
Ukrainian medal hope Natalia Semenova, the self-styled "Iron Lady", suffered a freak accident while warming up for the women's discus throw at ...

Resources last updated: 1/14/2016 1:48:13 PM