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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 convert TEXT to uniqueidentifier

Author  Topic 

pecunn
Starting Member

20 Posts

Posted - 2011-04-07 : 03:27:51
Hi admin,
I have query in here, which @PartyID is a report parameter as TEXT.
However now i try to convert @PartyID to uniqueIdentifier, i received an error 'The text, ntext, and image data types are invalid for local variables'.
I tried both cast and converter and received same error.
Not sure how to solve this.



DECLARE @StartPreviousFinancialYear NVARCHAR(4)
DECLARE @EndPreviousFinancialYear NVARCHAR(4)

DECLARE @StartCurrentFinancialYear NVARCHAR(4)
DECLARE @EndCurrentFinancialYear NVARCHAR(4)

SET @StartPreviousFinancialYear = DATEPART(YEAR,GETDATE()) - 2
SET @EndPreviousFinancialYear = DATEPART(YEAR,GETDATE()) - 1

SET @StartCurrentFinancialYear = @EndPreviousFinancialYear
SET @EndCurrentFinancialYear = DATEPART(YEAR,GETDATE())


SELECT
app.ApplicationSubTypeCode,
DATENAME(MONTH,app.LodgementDateTime) as 'month',
COUNT(*) as 'Number of DA'
FROM
Application app
WHERE
(app.LodgementDateTime BETWEEN ('01-Jul-' + @StartPreviousFinancialYear ) AND ('30-Jun-' + @EndPreviousFinancialYear ) )AND
app.ApplicationTypeCode = 'DA'
AND app.ClientID = CAST(@PartyID AS UNIQUEIDENTIFIER)
GROUP BY
app.LodgementDateTime,
YEAR(app.LodgementDateTime), MONTH(app.lodgementDateTime),
app.ApplicationSubTypeCode

cns1202
Starting Member

7 Posts

Posted - 2011-04-07 : 03:56:35
Just a thought..can you configure the @PartyId as Varchar(n), then you should not be getting such an error.

Regards,
Chirag Shah
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-07 : 04:07:44
You must have datatype conversion chart, always with you ;)
http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

pecunn
Starting Member

20 Posts

Posted - 2011-04-07 : 04:43:08
Its all working thanks.

Go to Top of Page
   

- Advertisement -