SQL help...
The Northern Monkey
Posts: 19,136
Ok this is beyond me so sorry if it makes no sense.
I currently use this code..
, isNULL (row1,0)
Which will bring back every result for the query, if there is no result it will show 0.
How do I get the NULL to bring a result from a different table instead of the 0?
ie.
row1 comes from "data 1" table. If row 1 isn't populated (ie NULL), I want to show the result from row1 on "data 2" table.
Sorry I can't be any more specific. Hopefully someone understands this more than I do!
I currently use this code..
, isNULL (row1,0)
Which will bring back every result for the query, if there is no result it will show 0.
How do I get the NULL to bring a result from a different table instead of the 0?
ie.
row1 comes from "data 1" table. If row 1 isn't populated (ie NULL), I want to show the result from row1 on "data 2" table.
Sorry I can't be any more specific. Hopefully someone understands this more than I do!
0
Comments
-
replace the zero with the select statement for what you want, ie. a nested select.Northwind wrote: It's like I covered it in superglue and rode it through ebay.0
-
aaaaaaaaaaaaaaaaa whatnow?
sorry i'm very new to this... the chap teaching me is leaving the company soon and he's hardly ever in the offfice0 -
Assume you have "Select k1, v1, isnull(v2,0) from Table1"
and instead of the 0 you want "Select v4 from Table2 where k2 = Table1.K1"
Simply substitute it in with some parenthesis around it.
Restriction: in this context the second query must always return one and only one row, so its usual to wrap v4 with an aggregate function.
I'm heading out to play table tennis and won't be back until 9ish. PM me with the actual queries and I'll put it together for you. Nested queries are about as complicated as you can get in SQL!Northwind wrote: It's like I covered it in superglue and rode it through ebay.0 -
BorisSpencer wrote:Nested queries are about as boring as you can get in SQL!
agreed.0 -
Ahh i get you... I didn't think i'd be able to run another query inside a query.0
-
-
sheepsteeth wrote:this thread is "query"
SQL is a queer.
I don't really enjoy it, but it keeps me busy when there's sod all else to do!0 -
to be fair, i have absolutely, completely and utterly no idea in the world what SQL is.
also, it sounds unbelieveably complicated and computery.
i just couldnt resist turning the word query into an innuendo.0 -
sheepsteeth wrote:to be fair, i have absolutely, completely and utterly no idea in the world what SQL is.
I most definately agree... I have no idea where my boss got the idea from that I know what i'm doing.
Still.... it beats having to go to sodding Baisingstoke tomorrow :evil:0