on 2013 Feb 19 6:48 PM
I have the following statement which works without error:
DECLARE @FormattedLicense NVARCHAR(255) SELECT @FormattedLicense = CAST ( CustomerID + '|' + AppName + '|' + MachineName + '|' + CAST (ExpirationDate AS VarChar(10)) + '|' + LicenseType AS NVARCHAR(255)) FROM RegisteredMachines INNER JOIN Licenses ON Licenses.LicenseID = RegisteredMachines.LicenseID WHERE RegistrationID = 1 SELECT @FormattedLicense
I would like to use this as a user-defined function, so I created one like this:
ALTER FUNCTION "DBA"."fFormatLicense" (@RegistrationID Unsigned BigInt) RETURNS NVARCHAR(255) AS BEGIN DECLARE @FormattedLicense NVARCHAR(255) SELECT @FormattedLicense = CAST ( CustomerID + '|' + AppName + '|' + MachineName + '|' + CAST (ExpirationDate AS VarChar(10)) + '|' + LicenseType AS NVARCHAR(255)) FROM RegisteredMachines INNER JOIN Licenses ON Licenses.LicenseID = RegisteredMachines.LicenseID WHERE RegistrationID = @RegistrationID RETURN @FormattedLicense END
Unfortunately, I get errors when I try to call this function.
DECLARE @Requested Unsigned BigInt SET @Requested = 1 SELECT fFormatLicense (@Requested)
There was an error reading the results of the SQL statement. The displayed results may be incorrect or incomplete. Cursor not in a valid state SQLCODE=-853, ODBC 3 State="24000" Right truncation of string data SQLCODE=-638, ODBC 3 State="22001"
I don't understand why my UDF doesn't work. Can anyone show me what to fix and how to fix it?
Request clarification before answering.
Right truncation of string data is an indicator that the server thinks you push a long string in a too small variable. I thought explict CAST prevents this.
Try to set the connection level option string_rtruncation option [compatibility] to off to verify if this is the cause of the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You Should you ether
SELECT CAST ( CustomerID + '|' + AppName + '|' + MachineName + '|' + CAST (ExpirationDate AS VarChar(10)) + '|' + LicenseType AS NVARCHAR(255)) INTO @FormattedLicense FROM RegisteredMachines INNER JOIN Licenses ON Licenses.LicenseID = RegisteredMachines.LicenseID WHERE RegistrationID = @RegistrationID;
or
set @FormattedLicense = ( select ... )
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
33 | |
21 | |
16 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.