|
Posted by Erland Sommarskog on 06/28/05 01:06
Axel (realraven2000@hotmail.com) writes:
> in T-SQL,
>
> (how) is it possible to concatenate 3 (varchar) fields into one; either
> in a SQL query or through a calculated field (or using a view, if
> anybody can explain to me how to use views), according to the following
> rules:
>
> {
> first 30 chars of Trim(AttributeVal1)
>
> if resulting string<30 chars append
> ", " & first 30 chars of Trim(AttributeVal2)
>
> if resulting string<30 chars append
> ", " & first 30 chars of Trim(AttributeVal3)
> }
>=> define as new field StockItemDescription
SELECT str30 = substring(rtrim(AttributeVal1)), 1, 30)
CASE WHEN len(AttributeVal1) < 30
THEN ', ' + substring(rtrim(AttributeVal2)), 1, 30)
CASE WHEN len(AttributeVal1) + 2
len(AttributeVal2) < 30
THEN ', ' + substring(rtrim(AttributeVal3)), 1, 30)
ELSE ''
END
END
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
[Back to original message]
|