sql server - Displaying 2 different length columns from SQL query when pulling from 1 table -


i use following code pull data table.

    select      case when vendorcontactlname '%[s]'         vendorcontactfname + ' ' + vendorcontactlname + '''' end 'test',     case when vendorcontactlname not '%[s]'         vendorcontactfname + ' ' + vendorcontactlname + '''s' end 'test2'     vendors; 

currently, returns 2 columns should, first condition isn't true, places "null" in test column , second condition isn't true, returns null in respective column. i'd not this, , instead incrementally add rows based on whether or not condition met , avoid rows null in them.

edit: not sure how wasn't clear, visual representation happen current code.

test            test2 null            francesco alberto's null            ania irvin's null            lukas liana's null            kenzie quinn's michelle marks' null null            anton mauro's null            ted maegen's null            erick kaleigh's null            kaitlyn anthoni's null            bill leigh's null            kaitlin hostlery's 

what want this:

    test            test2 michelle marks'    francesco alberto's                    ania irvin's                    lukas liana's                    kenzie quinn's                    anton mauro's                    ted maegen's                    erick kaleigh's                    kaitlyn anthoni's                    bill leigh's                    kaitlin hostlery's 

in case use outer query filter out null below. here xxx table alias inline query resultset.

select * (     select  case when vendorcontactlname '%[s]'     vendorcontactfname + ' ' + vendorcontactlname + '''' end 'test', case when vendorcontactlname not '%[s]'     vendorcontactfname + ' ' + vendorcontactlname + '''s' end 'test2'     vendors ) xxx test not null , test2 not null; 

(or)

using isnull() function like

select isnull(test, '') test, isnull(test2,'') test2 (     select  case when vendorcontactlname '%[s]'     vendorcontactfname + ' ' + vendorcontactlname + '''' end 'test', case when vendorcontactlname not '%[s]'     vendorcontactfname + ' ' + vendorcontactlname + '''s' end 'test2'     vendors ) xxx 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -