Hi
SQL
SELECT CASE
WHEN GroupID = 2 THEN
'' || GroupId || ''
END AS Grp
FROM GroupThanks
Hi
SELECT CASE
WHEN GroupID = 2 THEN
'' || GroupId || ''
END AS Grp
FROM GroupThanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 15, 2023, 7:02 AM EDT
SELECT CASE WHEN GroupID = 2 THEN ' ||' CAST(GroupId AS varchar) '|| ' Else CAST(GroupId AS varchar) END AS Grp FROM GroupRamco RamcoRank #462 · 5.4K reputationPosted Aug 15, 2023, 8:46 AM EDT
Hi Jignesh
It is simply printing like this -
||2|| . Below is the code
SELECT CASE WHEN GroupID = 2 THEN ' ||' + CAST(GroupId AS varchar) + '|| ' Else CAST(GroupId AS varchar) END AS Grp FROM [VivlioSyn].[dbo].[Group]Thanks
Tahir AnsariRank #366 · 6.8K reputationPosted Aug 14, 2023, 2:52 PM EDT
Hey Ramco Make sure that you have a column named "GroupID" in your "Group" table, and this query will generate a result column "Grp" with the HTML formatting for rows where GroupID equals 2.
SELECT CASE WHEN GroupID = 2 THEN '' || GroupID || '' END AS Grp FROM Group;If you are running this query in a database management tool or environment that displays query results as plain text, it won't interpret the HTML tags and instead, you'll see the raw HTML code as output.
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 15, 2023, 1:43 AM EDT
Hi Bhargavi
It is still giving error - Incorrect syntax near |
Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 15, 2023, 2:26 AM EDT
Hello Ramco,
You have missed else part in your query, please check below,
SELECT CASE WHEN GroupID = 2 THEN '' || GroupId || '' Else CAST(GroupId AS varchar) END AS Grp FROM GroupRamco RamcoRank #462 · 5.4K reputationPosted Aug 15, 2023, 2:51 AM EDT
Hi Jignesh
It is still giving same error . GroupId is int
SELECT CASE WHEN GroupID = 2 THEN '' || GroupId || '' Else CAST(GroupId AS varchar) END AS Grp FROM [Group] where GroupID = 2Ramco RamcoRank #462 · 5.4K reputationPosted Aug 15, 2023, 2:55 AM EDT
Hi Mohammad
It is just showing in output - 2
Thanks
Tasadduq BurneyRank #1,427 · 1.1K reputationPosted Aug 15, 2023, 3:39 AM EDT
Try this
SELECT CASE WHEN GroupID = 2 THEN '' + CAST(GroupId AS VARCHAR) + '' END AS Grp FROM [Group];Abhishek YadavRank #217 · 11.3K reputationPosted Aug 24, 2023, 5:31 AM EDT
It is just showing in output - 2
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 14, 2023, 1:57 PM EDT
Hi Ramco,
SELECT
CASE WHEN GroupID = 2 THEN
'' + GroupID + ''
END AS Grp
FROM Group
*******OR*********
SELECT
CASE
WHEN GroupId = 2 THEN
CONCAT('', GroupId, '')
END AS Grp
FROM
Group;
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 15, 2023, 4:57 AM EDT
Hi Burney
It is printing this . It is normal text. Style not getting implemented
2
Thanks
Prasad RaveendranRank #320 · 7.8K reputationPosted Aug 26, 2023, 10:09 PM EDT
Using
+operator (works for SQL Server, MySQL):SELECT CASE WHEN GroupID = 2 THEN '' + CAST(GroupId AS VARCHAR) + '' END AS Grp FROM "Group";If you provide information about the database you're working with, I can offer a more precise solution.
Cr BhargaviRank #420 · 5.9K reputationPosted Aug 14, 2023, 11:27 PM EDT
SELECT GroupID, CASE WHEN GroupID = 2 THEN '' || CAST(GroupId AS VARCHAR(10)) || '' ELSE CAST(GroupId AS VARCHAR(10)) END AS FormattedGroup FROM GroupTable;