Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL IN Operator for Concatenated values

ID News_Code News_Digits
1 GBX 400
2 NXC 670
3 LBO 880

I have several codes, what I need to check that code are in News_Code & news_Digit section. My code is like this:

'LBX 345','NXC 670'

What I have tried:

SELECT * 
FROM tblNews 
WHERE News_Code IN ('LBX 345', 'NXC 670')` // But here is the problem is not only the news_code we need to consider the News_Digit as well.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can concatenate the two columns and then compare:

SELECT * 
FROM tblNews 
WHERE News_Code + ' ' + News_Digits IN ('LBX 345', 'NXC 670')

If News_Digits is not a string data type, you can change that by casting it:

SELECT * 
FROM tblNews 
WHERE News_Code + ' ' + CAST(News_Digits AS VARCHAR(3)) IN ('LBX 345', 'NXC 670')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading