I have a query that extracts only two columns and trims one of the columns to only the media name. This is the query for that:
Select
[Object],
CASE WHEN MsgID = '61' THEN SUBSTRING(Parms,35,6) END AS [MEDIA]
from JnlDataSection
The results from this is:
Object --------- 061 STATEMENTS MEDIA --------- X01180 X01181
As you can see there are multiple medias for one object. What I want is a manual query in which I can just modify it with the object name and search one object with all of its respective medias and vice versa.
This is the query I came up with:
Select
[Object],
CASE WHEN MsgID = '61' THEN SUBSTRING(Parms,35,6) END AS [MEDIA]
WHERE [OBJECT] = '061 STATEMENTS'
from JnlDataSection
However I am receiving this error:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'from'.
Please Note: I'm using SQL Server Management Studio 2008.
UPDATE
After reading comments, I tried this query:
Select
[Object],
CASE WHEN MsgID = '61' THEN SUBSTRING(Parms,35,6) END AS [MEDIA]
from JnlDataSection
WHERE [MEDIA] = 'X05219'
It gave me this error:
Msg 207, Level 16, State 1, Line 5
Invalid column name 'MEDIA'.
How can I fix it?
SELECT...FROM...WHERE...GROUP BY...HAVING...ORDER BY. You have yourWHEREbefore yourFROM.SELECT. You need to either reproduce the case in theWHEREor redefine it in a table expression orCROSS APPLYWHERE CASE <your case logic> END = 'X05219'