sql - Adding Character to All Rows Returned from a SELECT -
i insert hyphen in middle of column rows of table. i'm pretty sure there built-in function this.
how can specify want hyphen placed within column?
test data declare @table table (mmdd_int int, mmdd_char varchar(4)) insert @table values (1201, '1201'), (1110, '1110'), (910 , '0910'), (101, '0101')
query select left(right('0'+cast(mmdd_int varchar(4)), 4),2) + '-' + right(cast(mmdd_int varchar(4)),2) int_column ,left(mmdd_char, 2) + '-'+ right(mmdd_char, 2) char_column @table
result ╔════════════╦═════════════╗ ║ int_column ║ char_column ║ ╠════════════╬═════════════╣ ║ 12-01 ║ 12-01 ║ ║ 11-10 ║ 11-10 ║ ║ 09-10 ║ 09-10 ║ ║ 01-01 ║ 01-01 ║ ╚════════════╩═════════════╝
sql sql-server
No comments:
Post a Comment