October 16, 2010 at 10:57 pm
I'm a newbie, I need help with sql query.
The requirement is : To get data from table which has column which has values example x=1 or Yes
Table:
ID varname varvalue
1 x 1
2 y yes
3 z no
.
.
select all records of table if varname=x and varvalue=1 or 'yes'
and varname=y and varvalue=2 or 'no'
How do we translate above req into sql query
Any help is greatly appreciated.
October 17, 2010 at 3:00 am
rtanda (10/16/2010)
I'm a newbie, I need help with sql query.The requirement is : To get data from table which has column which has values example x=1 or Yes
Table:
ID varname varvalue
1 x 1
2 y yes
3 z no
.
.
select all records of table if varname=x and varvalue=1 or 'yes'
and varname=y and varvalue=2 or 'no'
How do we translate above req into sql query
Any help is greatly appreciated.
hi , from what description you gave this shall work.
Declare @b-2 table
(
ID int,
varname varchar(10),
varvalue varchar(20)
)
insert into @b-2 values(1,'x','1')
insert into @b-2 values(2,'y','yes')
insert into @b-2 values (3,'z','no')
insert into @b-2 values (4,'y','no')
select * from @b-2 where (varname='x' and
(varvalue='1' or varvalue='yes')) or (varname='y' and
(varvalue='2' or varvalue='no'))
October 17, 2010 at 3:17 am
Sounds like a homework question.
If you use the answer from above without quoting the source (therewith stating it's not your solution) it'll be considered as plagiarism. It's cheating anyway.
Another story would have been if you had at least tried to solve it on your own, and if got stuck, ask for clarification/explanation together with what you've tried and what you need help with.
Other professionals around (on different threads) did remove their solutions as soon as the homework issue has been brought up. You might want to do the same 😉
October 18, 2010 at 7:55 pm
Thanks for quick reply
October 18, 2010 at 7:57 pm
Thanks for the quick reply sayedkhalid99
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply