Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to truncate row result?

Author  Topic 

dmilam
Posting Yak Master

185 Posts

Posted - 2010-05-14 : 13:19:28
[code]Select P.Description, P.Code, ...
from Promotion as P[/code]

This description is of type nvarchar(256); the results returned are only 9 characters long, so the remaining 247 characters are apparently 'filled out' with blanks, but this makes the result pane very wide, so that I have to scroll to the right to see the rest of the results. Yes, I could put the Description at the end, but I want to see it first.

Any way to have the result truncated exactly to the length of the text string returned?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 13:20:31
SELECT CONVERT(varchar(10), P.Description), ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-14 : 13:23:14
if problem is just viewing results in SQL management studio then why not use view in grid option (Ctrl + D). why change query for that?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 13:25:26
Because sometimes you need the result set in text so you can copy/paste it elsewhere in a good format, that's why I suggested CONVERT (for display purposes in SSMS only).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 13:26:26
I use the CONVERT method frequently to *quickly* send a small result set via email to people who don't have access to the database server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2010-05-14 : 13:27:45
Thanks, Tara! I do need the result in text format, so this is very helpful.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 13:28:56
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-14 : 13:31:23
but cant you do this copy paste also from grid format?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 14:02:01
Yes copy/paste works, however you don't get the column names plus the width gets screwed up. Text produces a nice format for a quick email.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-05-14 : 18:23:19
Tara - are you aware that you can now setup the grid options to include column headers? Personally, I do a cut/paste from the grid with this option turned on into an Excel spreadsheet. Users like this a lot better because then they don't have to import it themselves.

But, I agree - for quick and easy results to an email the text view works quite well.

I have used all of the above.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-14 : 18:28:51
I do see that the column headers are available in grid view with copy/paste by enabling that option, but it looks like it still junks up the result set.

I only use the copy/paste text method for email. Otherwise, I use bcp.exe although the column headers is a challenge there too, but it's still possible via a view.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-15 : 02:57:48
quote:
Originally posted by jeffw8713

Tara - are you aware that you can now setup the grid options to include column headers? Personally, I do a cut/paste from the grid with this option turned on into an Excel spreadsheet. Users like this a lot better because then they don't have to import it themselves.

But, I agree - for quick and easy results to an email the text view works quite well.

I have used all of the above.


I mostly use the grid format and i'm more comfortable with it.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-15 : 15:31:32
It just doesn't work well for very quick data into email, text option is best for that. We can agree to differ though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-17 : 05:23:27
quote:
Originally posted by visakh16

quote:
Originally posted by jeffw8713

Tara - are you aware that you can now setup the grid options to include column headers? Personally, I do a cut/paste from the grid with this option turned on into an Excel spreadsheet. Users like this a lot better because then they don't have to import it themselves.

But, I agree - for quick and easy results to an email the text view works quite well.

I have used all of the above.


I mostly use the grid format and i'm more comfortable with it.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




I too. But when it comes to perfect formation, text mode works good
In my blogpost, If I need to show the output, I use text mode to get it so that it has a good formation

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-05-17 : 09:52:04
good formation?

SUBSTRING(col,1,n)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -