Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234

VARCHAR datatype Expand / Collapse
Author
Message
Posted Monday, July 19, 2010 11:36 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, November 2, 2014 11:03 PM
Points: 2,132, Visits: 371
thanks, this explains everything...


DECLARE @Testvar VARCHAR;
SET @Testvar = 'Red';
print @Testvar;

Post #955295
Posted Tuesday, July 20, 2010 8:31 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, December 5, 2014 2:22 PM
Points: 1,586, Visits: 1,860
Excellent question! I don't think it's so much about relying on a default (bad practice) so much as forgetting to specify the length, which may not result in a syntax error, and may return results which are incorrect.
Thanks for the reality check.
Post #955624
Posted Tuesday, July 20, 2010 9:07 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 7, 2010 12:55 AM
Points: 771, Visits: 504
Excellent question. Defaults are always something to keep in mind and to avoid relying on, as they may change.
Post #955663
Posted Tuesday, July 20, 2010 10:34 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 14, 2014 3:50 AM
Points: 137, Visits: 650
Good question, got it wrong. Didn't know about default length being set to 1 if not declared. Nice job!

=============================================================
/* Backups are worthless, Restores are priceless */

Get your learn on at SQL University!
Follow me on Twitter | Connect on LinkedIn
My blog: http://sqlchicken.com
My book: Pro Server 2008 Policy-Based Management
Post #955746
Posted Monday, July 26, 2010 5:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 5:50 PM
Points: 7,924, Visits: 9,649
Good question. I got it wrong, because I didn't notice that the length wasn't specified. That will teach me not to skim read code when working out what it does (something I've often told others they must not do, but am still stupid enough to do it myself).

Tom
Post #959149
Posted Wednesday, July 28, 2010 5:47 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 11:41 AM
Points: 77, Visits: 218
Good question! I was shocked to see the four rows when I tried the query!

Leaving aside the issue of the COLLATION, I opted for the one row answer, because the first that came to mind was the default value of varchar in the CONVERT function, which is 30.

select convert (varchar, '123456789012345678901234567890123456789012345678901234567890 ')

Post #959956
Posted Tuesday, August 17, 2010 1:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 11:46 AM
Points: 10, Visits: 20
Because all colors are in proper case one can be led to believe that case sensitivity is a factor. To avoide this confusion it would be better to have all colors in lower or upper case.
Post #970168
Posted Wednesday, March 7, 2012 3:15 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Saturday, November 29, 2014 2:17 AM
Points: 483, Visits: 245
Nice and interesting question.
Post #1263324
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse