Thursday, March 2, 2023

[WAT] fun with declare @blah = varchar!

Another in my "WAT" file. (Go find it on youtube, you'll laugh and groan) 

What happens if you don't assign a length to varchar? I swear I'd learned that it became varchar(30).
Running on SQL Server 2014 SP3. Bold are the selects that are getting returned.

DECLARE @blah VARCHAR 
SET @blah = '123456' 
SELECT @blah 
DECLARE @date DATETIME=getdate() 
SELECT CONVERT(VARCHAR, @date, 112) 
SELECT @blah = CONVERT(VARCHAR, @date, 112) 
SELECT @blah 


2030302

2