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, Convert, and Case

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-25 : 12:42:45
I don't know why i thought i would be able to grasp this one on my own, but, well, here it is.

The issue is that i need to use the same sort of case expression already seen here to divert data that is too long for it's intended column, to another column in the same table that will hold much more data. The first problem is that the column to which i need to dump (now more than one column of overflow data, and append these strings together) is an old, deprecated data type (Text). Can't accomplish the Append operation on that type of field - not allowed. I need to cast and convert the "CheckNo" field to a varchar(max) and append it to the data that is already going into the "comments" field with a hardcoded prefix of "The Check numbers in this case are: ".

As of now, i'm unsure of how the syntax for adding that cast and convert statement will fit into what i already have here:

INSERT INTO CIVIL.dbo.RECEIPTS
(
RECEIPTNO,
RECEIVEDATE,
TYPEWRIT,
PLAINTIFF,
DEFENDANT,
COURTNAME,
CASENO,
CHECKNO,
REFUNDDATE,
REFUND,
ATTORNEYID,
COMMENTS,
UNIQUEKEY,
ProcessTypeFKey
)
VALUES
(
'GCSO1110000000000ENF',
'1/2/2007',
'ORDER OF CONTEMPT AND WARRANT FOR COMMITMENT',
'COMMERCE CREDIT UNION',
'Jane Doe',
'COUNTY-LEON',
CASE
WHEN LEN('2004 SC 2135 ') > 20 THEN 'See Comments'
ELSE ' 2004 SC 2135'
END,
'35801',
'1/2/2007',
'0',
'382',
CASE
WHEN LEN('2004 SC 2135') > 20 THEN 'The Case Number is 2004 SC 2135'
ELSE ''
END,
SCADMIN.dbo.fnsc_GetUniqueID(NEWID()),
'3H4Lx74A10kfKsjyvc2Ymf'
);

Any guidance is appreciated.

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-25 : 12:51:21
I should also add that the CE for the "CheckNo" column should evaluate the Length of the string. If it is more than 10 characters, it should place "See Comments" in the CheckNo column.
Go to Top of Page
   

- Advertisement -