July 8, 2011 at 2:39 pm
Hi All,
I have an issue, Where I have a set of values in the where clause, In those set of values, A few values are tied with other values.
How do I write where clause for that sitiation.
Example:
where abc in (1, 2, 3, 4, 5, 6)
For these six values abc in (1, 2, 3, 4) should also have cde in (123, 452, 78, 124, 458).
How do I write a where clause for this?
Thanks.
July 8, 2011 at 2:51 pm
something like where abc in (5, 6)
OR (abc in (1, 2, 3, 4) AND cde in (123, 452, 78, 124, 458))
July 8, 2011 at 2:55 pm
It's unclear what you are asking. Could you give a better example of the data in table form.
ie
PRINT 'Declare variable table'
DECLARE @table TABLE
(id int
,a int
,b int
)
PRINT 'Insert values in the table'
INSERT INTO @table (id,a,b) values (1,1,123);
INSERT INTO @table (id,a,b) values (2,2,452);
INSERT INTO @table (id,a,b) values (3,3,78);
INSERT INTO @table (id,a,b) values (4,4,124);
INSERT INTO @table (id,a,b) values (5,5,458);
INSERT INTO @table (id,a,b) values (6,6,857);
PRINT 'Test the load'
SELECT * FROM @table
July 8, 2011 at 4:35 pm
Thanks Lutz, That worked.
LutzM (7/8/2011)
something likewhere abc in (5, 6)
OR (abc in (1, 2, 3, 4) AND cde in (123, 452, 78, 124, 458))
July 8, 2011 at 4:37 pm
Thanks eccentricDBA,
Lutz solution explains what my issue was.
eccentricDBA (7/8/2011)
It's unclear what you are asking. Could you give a better example of the data in table form.ie
PRINT 'Declare variable table'
DECLARE @table TABLE
(id int
,a int
,b int
)
PRINT 'Insert values in the table'
INSERT INTO @table (id,a,b) values (1,1,123);
INSERT INTO @table (id,a,b) values (2,2,452);
INSERT INTO @table (id,a,b) values (3,3,78);
INSERT INTO @table (id,a,b) values (4,4,124);
INSERT INTO @table (id,a,b) values (5,5,458);
INSERT INTO @table (id,a,b) values (6,6,857);
PRINT 'Test the load'
SELECT * FROM @table
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply