SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


String or binary data would be truncated.The statement has been terminated.


String or binary data would be truncated.The statement has been terminated.

Author
Message
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1819 Visits: 715
Hi there - Me again I'm afraid.

I am running the following code which I am in the process of putting together -

INSERT INTO Customers 
(
RecordStatusID,
CreatedDate,
CreatedTime,
CreatedByID,
Residential,
ShortName,
ShortCode,
SiteTypeID,
[Name],
Address,
City,
ProvinceCountyID,
StateCountyID
)




SELECT 0 AS RecordStatusID
,GETDATE() AS CreatedDate
,{ fn NOW() } AS CreatedTime
,2 AS CreatedByID
,0 AS Residential
,CASE WHEN PROP.postcode IS NULL
THEN PROP.address
ELSE PROP.postcode + N'/' + PROP.address
END AS ShortName
,'' AS ShortCode
,0 AS SiteTypeID
,'' AS Name
,PROP.address
,PROP.city
,0 AS ProvinceCountyID --Need to clear this with Solarvista
,0 AS StateCountyID

FROM DataWarehouse.dbo.HEX_PROP_AND_UNIT AS PROP



When I run the code I get the following error -

Server: Msg 8152, Level 16, State 6, Line 1
String or binary data would be truncated.
The statement has been terminated.

I think I know why it is.

The ShortName in the Customers table is limited to 30 characters (Datatype nvarchar) but because of the way I am making the Shortname in my Select statement via the CASE it is exceding the 30 characters.

How can I limit this is just 30 characters in my SELECT STATEMENT?

Thanks

Ryan
inampudianil
inampudianil
SSC Veteran
SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)

Group: General Forum Members
Points: 234 Visits: 374
i guess try it with //(double slash )in case staement
Thnx Anil
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34965 Visits: 16664
Ryan

That all depends on your requirements. Here's one way (not tested):

...
LEFT(COALESCE(PROP.postcode + N'/','') + PROP.address ,30)
...



John
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1819 Visits: 715
In my CASE statement I want my results to be limited to 30 characters.

So in the ELSE part of the statement I have

ELSE PROP.postcode + N'/' + PROP.address, it is this that I want limited.

Thanks

Ryan
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34965 Visits: 16664
Ryan

But how do you want to limit it? First 30 characters? Last 30 characters? Remove all vowels? If you want the first 30 characters, use the code snippet I provided earlier. You'll notice that because it uses COALESCE, you don't need a CASE statement.

John
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1819 Visits: 715
Oh sorry John. It is limied to the first 30 characters. I will give it a go.

Thanks
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1819 Visits: 715
Just to say Thanks.

This worked.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search