SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CAST function....
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 09/08/2008 :  13:53:17  Show Profile  Send ZarrinPour a Yahoo! Message  Reply with Quote
Hi
i want to know when i use cast function to convert a numeric data to varchar value, if i don't provide length,what does it mean?

Kind Regards.

Nothing is quite impossible!

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 09/08/2008 :  13:58:45  Show Profile  Reply with Quote
get used to checking Books Online - It's a great source.
quote:

Syntax for CAST:
CAST ( expression AS data_type [ (length ) ])

length
Is an optional parameter of nchar, nvarchar, char, varchar, binary, or varbinary data types. For CONVERT, if length is not specified, the default to 30 characters.



Be One with the Optimizer
TG
Go to Top of Page

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 09/08/2008 :  14:05:09  Show Profile  Send ZarrinPour a Yahoo! Message  Reply with Quote
Hi TG

quote:

Originally posted by TG

get used to checking Books Online - It's a great source.
[quote]
For CONVERT, if length is not specified, the default to 30 characters.


I've already read this in BOL, BUT what about CAST?

Kind Regards.

Nothing is quite impossible!
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 09/08/2008 :  14:12:44  Show Profile  Reply with Quote
I didn't notice the "for CONVERT" but I assume its the same for CAST. This little test seems to confirm it:

use tempdb
select cast(0 as varchar) test into #t
exec sp_help #t

OUTPUT:

Column_name                     Type                 Computed                            Length 
---------------------------------------------------------------------------------------- -------
test                            varchar              no                                  30     



Be One with the Optimizer
TG
Go to Top of Page

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 09/08/2008 :  14:21:55  Show Profile  Send ZarrinPour a Yahoo! Message  Reply with Quote
Thanks sooo much.

Nothing is quite impossible!
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 09/08/2008 :  15:16:04  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Now you've learned the two steps to being a good programmer: If you have a question, first check the documentation. If that doesn't answer it, just write a simple test.

- Jeff
http://weblogs.sqlteam.com/JeffS

Edited by - jsmith8858 on 09/08/2008 15:16:42
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22774 Posts

Posted - 09/09/2008 :  02:38:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also read http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.31 seconds. Powered By: Snitz Forums 2000