July 27, 2011 at 3:50 pm
Is it possible to concatenate a small int field and a bit field
i have two fields as Id and isactive id is smallint and ISactive is a bit field, i have to query these two but want to produce the result in a single column with concatenation
any ideas
** it doesn't work with CAST
July 27, 2011 at 3:52 pm
Well ya, convert both to varchar(x) and then concat.
But why do you need to do this? Never seen that before...
July 27, 2011 at 4:16 pm
Here's a quick demo SQLTestUser to show the technique:
IF OBJECT_ID(N'tempdb..#temp_table') > 0
DROP TABLE #temp_table ;
CREATE TABLE #temp_table
(
type_smallint SMALLINT,
type_bit BIT
) ;
INSERT INTO #temp_table
(type_smallint, type_bit)
VALUES (0, 0),
(0, 1),
(1, 0),
(1, 1) ;
GO
SELECT CAST(type_smallint AS VARCHAR(5)) +
CAST(type_bit AS CHAR(1)) AS my_concat_value
FROM #temp_table ;
GO
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 27, 2011 at 4:30 pm
Thanks it worked like a charm
July 27, 2011 at 4:35 pm
Sure, HTH 🙂
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 28, 2011 at 6:15 am
Just an FYI, trying to concat anything numerical tends to add it, not to concat it. So you will always need to convert numbers to strings before concateonating to make sure they don't decide to sum themselves up.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply