Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by bitbucket
»
DECLARE - 1
49 posts, Page 1 of 5
1
2
3
4
5
»
»»
DECLARE - 1
Rate Topic
Display Mode
Topic Options
Author
Message
bitbucket-25253
bitbucket-25253
Posted Tuesday, October 02, 2012 8:14 PM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 9:12 PM
Points: 5,103,
Visits: 20,208
Comments posted to this topic are about the item
DECLARE - 1
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please
read
Before posting a performance problem please
read
Post #1367377
Lokesh Vij
Lokesh Vij
Posted Tuesday, October 02, 2012 10:05 PM
Ten Centuries
Group: General Forum Members
Last Login: Yesterday @ 8:24 AM
Points: 1,176,
Visits: 1,253
Thanks for this easy point Ron in the middle of the week
~ Lokesh Vij
Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions
Link to my Blog Post -->
www.SQLPathy.com
Follow me
@Twitter
Post #1367390
Koen Verbeeck
Koen Verbeeck
Posted Tuesday, October 02, 2012 11:06 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 6:39 AM
Points: 9,376,
Visits: 6,472
Oldie but a goodie
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1367404
kapil_kk
kapil_kk
Posted Tuesday, October 02, 2012 11:31 PM
Ten Centuries
Group: General Forum Members
Last Login: Sunday, May 19, 2013 11:16 PM
Points: 1,061,
Visits: 1,151
can anyone explain me why select len(@a) as 'declared' gives output as 1
Post #1367407
Kingston Dhasian
Kingston Dhasian
Posted Wednesday, October 03, 2012 12:47 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 10:46 PM
Points: 2,231,
Visits: 4,200
kapil190588 (10/2/2012)
can anyone explain me why select len(@a) as 'declared' gives output as 1
The answer to this is available in the explanation to the question( also shown below )
When n (Where n defines the string length) is not specified in a data definition or variable declaration statement, the default length is 1
Hence the two declaration shown below are equivalent
DECLARE @a VARCHAR ='xyz'
DECLARE @a VARCHAR(1) = 'xyz'
Kingston Dhasian
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1367416
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
Posted Wednesday, October 03, 2012 1:10 AM
Hall of Fame
Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 3,129,
Visits: 4,312
Easy one for middle of the week, thanks Ron
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1367423
kapil_kk
kapil_kk
Posted Wednesday, October 03, 2012 1:19 AM
Ten Centuries
Group: General Forum Members
Last Login: Sunday, May 19, 2013 11:16 PM
Points: 1,061,
Visits: 1,151
thanks Kingston..
Post #1367429
Stuart Davies
Stuart Davies
Posted Wednesday, October 03, 2012 2:12 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 1:41 AM
Points: 2,476,
Visits: 2,140
Thanks Ron - easy one for me today
-------------------------------
Posting Data Etiquette - Jeff Moden
Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
Post #1367456
Toreador
Toreador
Posted Wednesday, October 03, 2012 2:52 AM
Ten Centuries
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:52 AM
Points: 1,356,
Visits: 4,761
As usual the lesson is not to rely on the defaults.
I'd have expected a near 100% success rate given the number of similar questions we've had in recent months, but obviously it still needs repeating!
Post #1367471
Praveena-487125
Praveena-487125
Posted Wednesday, October 03, 2012 2:53 AM
Valued Member
Group: General Forum Members
Last Login: Friday, May 10, 2013 12:26 AM
Points: 55,
Visits: 66
Got to know that by default it takes the length as 1 if the size is not declared. Thank you....
However, I still did not get the difference between length of normal declaration and Cast/Convert... Please find below the queries....
1) SELECT
LEN('xyz') AS 'Declared'
, LEN(CONVERT(VARCHAR,'xyz')) AS 'Converted'
, LEN(CAST('xyz' AS VARCHAR)) AS 'Cast'
Ans : 3,3,3
2)
DECLARE @a VARCHAR ='xyz'
SELECT
LEN(@a) AS 'Declared'
, LEN(CONVERT(VARCHAR,@a)) AS 'Converted'
, LEN(CAST(@a AS VARCHAR)) AS 'Cast'
Ans : 1,1,1
I did not get default of 30 (which you mentioned in the answer in case of Cast/Convert) in what ever way I try... Can you please explain more on this?
Post #1367472
« Prev Topic
|
Next Topic »
49 posts, Page 1 of 5
1
2
3
4
5
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.