Because when you declare
, default varchar
length is 1
. So @MyVarchar
ends up being 'A'
.
This is different to cast(something as varchar)
, where default length is 30
.
The right thing is
DECLARE @MyVarchar varchar(10) = 'ABCDEF';
where 10
is the length of the column in the table.
More Related Contents:
- SQL NVARCHAR and VARCHAR Limits
- How do you use script variables in psql?
- Calculating distance between two points (Latitude, Longitude)
- How do I use variables in Oracle SQL Developer?
- How to declare variable and use it in the same Oracle SQL script?
- How to rewrite IS DISTINCT FROM and IS NOT DISTINCT FROM in SQL Server 20008R2?
- Declare variable in SQLite and use it
- T-SQL split string based on delimiter
- Partition Function COUNT() OVER possible using DISTINCT
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server [duplicate]
- Cannot use UPDATE with OUTPUT clause when a trigger is on the table
- How to return the output of stored procedure into a variable in sql server
- CASE WHEN statement for ORDER BY clause
- How to get last 7 days data from current datetime to last 7 days in sql server
- Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)
- Reference an alias elsewhere in the SELECT list
- Count Returning blank instead of 0
- How to Split String by Character into Separate Columns in SQL Server
- Coldfusion – variable field name when looping through database query results
- Using IF ELSE statement based on Count to execute different Insert statements
- Passing dynamic order by in stored procedure
- move cells left in sql if left contains null and right contains value
- Select SQL Server database size
- Check if table exists and if it doesn’t exist, create it in SQL Server 2008
- How do I find the data directory for a SQL Server instance?
- How to return default value from SQL query
- Store and reuse value returned by INSERT … RETURNING
- How to concatenate all columns in a select with SQL Server
- T-SQL calculate moving average
- How to automatically generate unique id in SQL like UID12345678?