April 18, 2013 at 6:17 am
Hi all,
Is it possible to add a prefix to a returned result in a view in sql.
eg
select productId
from Table1
returns
id1
id2
id3
I would like to put a set value(prefix) to the returned result eg http://www.john.com/
returning the following
is this possible ?
thanks very much
John.
April 18, 2013 at 6:20 am
Is ProductID a string type or an integer?
April 18, 2013 at 6:22 am
Product ID is an integer but im trying to add a string to it. I can change it to a varchar if needed as there isnt that many products so speed is not an issue
April 18, 2013 at 6:23 am
DECLARE @table1 TABLE
(
ProductId INT
)
INSERT INTO @table1
SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
SELECT
'www.john.com/' + convert(varchar(50),productid)
FROM
@table1
Use the CONVERT() function or CAST()
April 18, 2013 at 6:28 am
Thanks very much, i had this working in the past but couldnt remember how I did it or find an answer.
Solved.:-)
April 18, 2013 at 6:30 am
Hi dallibabs,
try this query.
select 'www.john/'+Convert(varchar,productId) as id from Table1
--chalam
April 18, 2013 at 6:40 am
chalam87 (4/18/2013)
Hi dallibabs,try this query.
select 'www.john/'+Convert(varchar,productId) as id from Table1
Remember to specify a length in you convert() for the varchar. Otherwise you will end up with some strange truncation errors.
April 18, 2013 at 6:52 am
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply