![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi All, Hope someone can help to solve this SQL question. I have the following table called '#temptable' (it is a temp table) source price state A 1 NY B 2 NY C 3 NY B 4 CA C 5 CA C 6 TX I need a SQL statement that performs the following pesudo code: if source A exists then (select * from #temptable where source = 'A') if source A not exists then check if source B exist. if source B exists then (select * from #temptable where source = 'B') if source B not exists then check if source C exist. if source C exists then (select * from #temptable where source = 'C') if source C not exists then print 'Nothing is found.' The following code can be used to create the temp table for testing: create table #TempTable (source char(1), price int, state char (2)) insert into #TempTable values ('A', 1, 'NY') insert into #TempTable values ('B', 2, 'NY') insert into #TempTable values ('C', 3, 'NY') insert into #TempTable values ('B', 4, 'CA') insert into #TempTable values ('C', 5, 'CA') insert into #TempTable values ('C',6, 'TX') Thanks. SQL Learner |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |