Hi I have 2 coloumn one hast char(Productname) type another has int type (CustomerID)I want to contact them in my stored procedure like:
select Productname+CustomerID az newID
but I have error becouse one of them are int another in char ddo you have any idea?
I suggest that you read about "Datatype Precedence" in Books Online. It will explain what that fail. SQL
Server will try to convert the string to an int. You have to use an explicit CAST:
SELECR Productname + CAST(CustomerID AS varchar(20))
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"mahsa" <anonymous@.discussions.microsoft.com> wrote in message
news:F40E28D3-9983-4229-9BDC-ECCF73F4E229@.microsoft.com...
> Hi I have 2 coloumn one hast char(Productname) type another has int type (CustomerID)I want to contact them
in my stored procedure like:
> select Productname+CustomerID az newID
> but I have error becouse one of them are int another in char ddo you have any idea?
|||mahsa
CREATE TABLE #Test
(
col INT,
col1 VARCHAR(10)
)
GO
INSERT INTO #Test VALUES (1,'AA')
INSERT INTO #Test VALUES (2,'BB')
GO
SELECT CAST(col AS VARCHAR(10))+col1 FROM #Test
"mahsa" <anonymous@.discussions.microsoft.com> wrote in message
news:F40E28D3-9983-4229-9BDC-ECCF73F4E229@.microsoft.com...
> Hi I have 2 coloumn one hast char(Productname) type another has int type
(CustomerID)I want to contact them in my stored procedure like:
> select Productname+CustomerID az newID
> but I have error becouse one of them are int another in char ddo you have
any idea?
|||thank you it works
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment