| 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.
>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')