ms sql server - manage appearance of the query...

Im trying to create a simple autocomple on my asp.net/vb.net web form..I hear usercontrols are nicer..but im going the cheap route with this..this query will then pull into a dropdown box on my web form.  the query works, however I am wantingthe columns to line up and right now they dont. Any suggestions?

so for example there are 4 columns and they look like this:
[dddd ] [rrrr][ ] [hhhhhhhhh]
[hh][ssssssssss][aaa][eeeeeeeeee]

when it needs to look like this:
[dddd ] [rrrr          ][     ][hhhhhhhhh]
[hh    ] [ssssssssss ][aaa][eeeeeeeeee]


the columns should line up...

below is the query, if you run it with your own data you will see what I am saying...
SELECT '[' + LEFT(cast(name as nvarchar(max)),30) + '] [' + LEFT(cast(city as nvarchar(max)),20) + '] [' + LEFT(cast(shoeid as nvarchar(max)),20) + '] [' + LEFT(cast(shoetype as nvarchar(max)),20) + ']' 
                         FROM  shoe descrpt 
                         WHERE name like '%q%'
                         and  Type <> 'shoe' 
                         ORDER BY Name ASC

Open in new window

LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
 
Eric3141Commented:
Using varchar I'm not sure that's possible as obviously the width of each column is variable.  If you use CHAR datatype instead then column widths would be consistent but you would have spaces at the end of the field values.  If you can live with that then try char instead of varchar.

Also I noticed that you used varchar(max) but you only wanted to use the left most 30 characters.  varchar(max) is for when you have > 4,000 characters in nvarchar format I think.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.