sql - Determine correct column in dataset -
sql - Determine correct column in dataset -
i need remap info export. info beingness pulled multiple tables view.
in view pertinent columns , illustration values are:
size_bucket size_desc 2 xs 3 s 4 m 5 l 6 xl
size bucket corresponds column in table contains various size descriptions; example:
size02 size03 size04 size05 size06 xs s m l xl
the problem export, values of size_bucket wrong , don't correspond related sizexx column in other table. have table right mappings contain right values various sizexx columns.
what need determine column contains right value , switch out value of size_bucket right corresponding sizexx column.
so right values in mapping table have
size02 size03 size04 size05 size06 size07 xxs xs s m l xl
finally, here sample psuedo query i'm trying create right values size_bucket:
select case (u.sizebucket) when '1' u.sizebucket when '2' case when u.size_desc = k.size02 '2' end case when u.size_desc = k.size03 '3' end /* , on different sizexx columns */ when '3' /* repeat above code */ /* repeat when sizes */ end size_bucket, k.size_name, u.size_desc, k.size01, k.size02, k.size03, k.size04, k.size05, k.size06, k.size07, k.size08, k.size09, k.size10, k.size11, k.size12, k.size13, k.size14, k.size15 exportview u inner bring together size_map_table k on u.size_code = k.size_code
any suggestions or ideas on how in much simpler way appreciated. i'm not sure yet if way have in mind here work yet.
here info examples per request:
for view columns nvarchar, likewise in mapping table.
some sample info in view:
size_code size_desc size_bucket lds xs 3 lds s 4 lds m 5 ldn 0 2 ldn 2 3 ldn 4 4
in mapping table:
size_code size01 size02 size03 size04 size05 lds xs lds s lds m ldn 0 ldn 2 ldn 4
expected results right values size_bucket
this:
size_code size_desc size_bucket lds xs 2 lds s 3 lds m 4 ldn 0 1 ldn 2 2 ldn 4 3
sql sql-server-2008
Comments
Post a Comment