Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning an additional row (error) when only 1 row is returned

Status
Not open for further replies.

WMitchellCPQ

Programmer
Sep 28, 2001
54
0
0
US
I am using a two SQL Querys - one is nested inside the other. I want to have the subquery (Query 2) generate an additional row if only one row is returned. Any ideas

Query 1:
Select TOP 1 * WHERE asdf = "XX" ORDER BY asdf ASC
{
Query 2:
Select TOP 2 * WHERE bla = "YY" ORDER BY bla DESC
}

Thanks as always
W
 
It's not clear what you are asking, but one solution that should work no matter what you are asking is to use an IF statement. This is probably not the best way, but without a clear understanding of what you want, it's the best I can do.
IF 1=(Select count(*) From SomeTable Where SomeCondition)
SomeQuery
ELSE
SomeOtherQuery
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top