sqlshots: SELECT-TRIM-CASE-CONCAT

In this particular scenario I need to concatenate a set of fields into a single coumn. So essentially I needed to trim all the leading zeros from the street number field first (via my udf_TrimLeadingZeros), then pieced the street number, pre-direction, street name and suffix all into one field. However, every row did not have a pre-direction nor a suffix; nonetheless, I needed everything formatted (even spaced between words) and displayed as a single string.

So I figured I would use a CASE expression (http://bit.ly/PiYQF) in conjunction with a String Concatenation (http://bit.ly/FJtq9) to achieve my end results. Typically I see a period (.) appended to the pre-direction, but in this case it wasn't required. However if you do need it simply add a period to line 14 between the ticks '. ' of the attached select script (see pre-direction with periods screen shot for details).

Pre-Direction without periods

Pre-Direction with periods

Click here to download:
CREATE.udf_TrimLeadingZeros_v0.01.sql (0 KB)

Click here to download:
SELECT.Trim-Case-ConCat_v0.01.sql (0 KB)

Posted via email from wetmatter nonsense

0 comments: