I currently have the following SQL Query:
SELECT
con_Content,
cot_Name,
pag_Name
FROM
[Page]
inner join [Content] on con_PageID = pag_ID
inner join [ContentType] on cot_ID = con_TypeID
WHERE
pag_URL = 'tour'
that returns multiple rows like the screenshot below:
https://i.stack.imgur.com/2GbHi.gif
i really need this query to return 1 row with the additional column names to be ‘LeftColumn’, ‘RightColumn’, ‘MainContent’ and the value of those columns to be the ‘con_content’ .
My SQL is not very good right now.
As mentioned by @Donnie, it sounds like you want to do a pivot. If this is for SQL Server 2005 or later:
and if this is not SQL Server 2005+:
Edit
If there is no corresponding
cot_Namevalue for a field in the pivot list, the query will still execute and returnnullfor that field.For example, try this:
So in your case, you could include every value you are interested in, and just check for
nullto see whether thepag_Namehas any content for thatcot_Name: