By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

Help me with SQL

100+
P: 107
i have a table with coulmns as C1, C2, C3, C4 which contains datas like A, B, C & D. Now how should i select records where the data is A in any one of this column. I mean i want to select records which has A as the data in any one of this columns.

Please advise me!
Mar 13 '09 #1
Share this Question
Share on Google+
1 Reply


P: 10
Hi,

I do not understand the actual scenario what u are looking for,But you could try something like this..Hope this helps you :)

IF EXISTS(SELECT Name FROM SysObjects WHERE Name = 'ABCD')
BEGIN
DROP TABLE ABCD
END
GO
create TABLE ABCD
(
C1 varchar(25),
C2 Varchar(25),
C3 Varchar(25),
C4 Varchar(25)
)
GO
INSERT INTO ABCD(C1, C2 , C3 , C4)
VALUES('A','B','C', 'D')
GO
INSERT INTO ABCD(C1, C2 , C3 , C4)
VALUES('B','C','D', 'A')
GO
INSERT INTO ABCD(C1, C2 , C3 , C4)
VALUES('C','B','A', 'D')
GO
INSERT INTO ABCD(C1, C2 , C3 , C4)
VALUES('B','A','C', 'D')
GO
INSERT INTO ABCD(C1, C2 , C3 , C4)
VALUES('X','Y','Z', 'Z')
GO

SELECT * FROM ABCD WHERE C1 = 'A'
UNION ALL
SELECT * FROM ABCD WHERE C2 = 'A'
UNION ALL
SELECT * FROM ABCD WHERE C3 = 'A'
UNION ALL
SELECT * FROM ABCD WHERE C4 = 'A'
Mar 13 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.