Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Cast & Comma in output parameter

Author  Topic 

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-07-10 : 02:47:23
Hello

i need to add a comma to each output and got this error
'Error converting data type varchar to bigint'
Not sure how to cast @CompanyID with bigint. @CompanyID does not have null value.
Tried all 3 queries but none work..

Alter PROCEDURE [dbo].[sp_GetCompany]
@CompanyID bigint OUTPUT
AS
SET NOCOUNT ON;
SELECT @CompanyID = t1.CompanyID + ','
FROM t1
WHERE EXISTS
(Select 1
FROM t2 d
where d.CompanyID=t1.CompanyID
union all
SELECT 1
FRPM t3 e
WHERE e.CompanyID=t1.CompanyID
)
GO



Error: A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

SELECT @CompanyID = CAST(@CompanyID AS varchar(20))+ ',', '' +
[CompanyID]
FROM t1



SELECT @CompanyID = ISNULL(@CompanyID + ',', '') + [CompanyID]
FROM t1
WHERE EXISTS
(Select 1
FROM t2 d
where d.CompanyID=t1.CompanyID
union all
SELECT 1
FRPM t3 e
WHERE e.CompanyID=t1.CompanyID

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-10 : 03:00:23
declare @string varchar(...)

SELECT @string = ISNULL(CAST(@string AS VARCHAR(...))+ ',', '') + CAST([CompanyID] AS VARCHAR(...))
FROM t1
WHERE EXISTS
(Select 1
FROM t2 d
where d.CompanyID=t1.CompanyID
union all
SELECT 1
FRPM t3 e
WHERE e.CompanyID=t1.CompanyID


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-07-10 : 04:21:34
Thank you!
Go to Top of Page
   

- Advertisement -