searchsanjaysharma
asked on
How to write complex sql query?
Tablename - trainers
Fields: tid,trainername,flag
tid is unique primary key
trainerana,e is name of the trainer
flag contains either 0 or 1.
Write a query that returns all the trainers with thier tid and trainername.The output should replace tid with blank for those trainernames where flag is set to 1
Fields: tid,trainername,flag
tid is unique primary key
trainerana,e is name of the trainer
flag contains either 0 or 1.
Write a query that returns all the trainers with thier tid and trainername.The output should replace tid with blank for those trainernames where flag is set to 1
oops
select case when flag = 1 then '' else cast( tid as varchar ) end as tid ,trainername,flag
from trainers
select case when flag = 1 then '' else cast( tid as varchar ) end as tid ,trainername,flag
from trainers
or try this:
select tid,trainername from trainers where flag <> 1
union all
select '' ,trainername from trainers where flag = 1
select tid,trainername from trainers where flag <> 1
union all
select '' ,trainername from trainers where flag = 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this appears to be "Homework"/"Coursework" we are limited to what we can provide for such questions ...
please confiirm the background for your requirement....
please confiirm the background for your requirement....
ASKER
This is not the homework for your kind informationl
secondly when i am paying i am suppose to get response and accept what suits my need.
thirdly i could easily wirte sp for it. but i wanted the answer in 1 sql statement.
Anyways thanks for your Guess.
secondly when i am paying i am suppose to get response and accept what suits my need.
thirdly i could easily wirte sp for it. but i wanted the answer in 1 sql statement.
Anyways thanks for your Guess.
ASKER
THANKS
ASKER
Thanks for your valuable comments.
ASKER
ok
from trainers