Simple way to concatenate BIT and NVARCHAR columns
MyTable
=======
Item NVARCHAR(200)
Hidden BIT
I need to load all the items from MyTable
in a DropDownList
in such format: Item (Hidden)
This how my list would look like:
Brush
Table (Hidden)
Box (Hidden)
PC
Ball
N.B: I've reached in my search to this SQL entry:
SELECT ID, Item + '(' 开发者_如何学JAVA+ CAST(Hidden AS NVARCHAR(200)) + ')' AS Conct
FROM Items
Which Returns Item(0) or Item(1)
..I can't think of a simple way to use for my purpose but I thought I'd change the Hidden column to NVARCHAR and store hidden or blank in it .. or maybe add another column that stores the word 'Hidden' for any '1' in the Hidden (BIT) column. What do you think guys ?
You can use the CASE statement:
SELECT ID,
Item + (CASE Hidden WHEN 1 THEN ' (Hidden)' ELSE '' END) AS Conct
FROM Items
You could do a CASE:
SELECT ID, Item + (CASE Hidden
WHEN 1 THEN '(Hidden)'
ELSE ''
END) AS Conct
FROM Items
Adding another column for the word 'Hidden' when Hidden is 1 would be redundant.
精彩评论