Curly braces in T-SQL

These are ODBC escape sequences. See Date, Time, and Timestamp Escape Sequences for more details.

There is also similar syntax for uniqueidentifiers

SELECT {guid '00000000-0000-0000-0000-000000000000'},

as well as procedure calls and some other constructs detailed off that link.

With regard to the rest of your question I’m not aware of any way of having an integer literal treated as a bigint or of any particular resource that lists all the ways of influencing how literals are assigned datatypes by SQL Server. Some ways are below.

;WITH cte(thing) AS
(
SELECT CAST(1 AS SQL_VARIANT) UNION ALL
SELECT $1 UNION ALL
SELECT 1e0 UNION ALL
SELECT 1.0000 UNION ALL
SELECT 2147483648 UNION ALL 
SELECT {ts '2011-09-15 01:23:56.123'}  UNION ALL
SELECT {d '2011-09-15'} UNION ALL
SELECT { t '13:33:41' }  UNION ALL
SELECT {guid '00000000-0000-0000-0000-000000000000'} UNION ALL
SELECT 'Foo' UNION ALL
SELECT N'Foo'
)
SELECT thing, 
       sql_variant_property(thing,'basetype') AS basetype,
       sql_variant_property(thing,'precision') AS precision, 
       sql_variant_property(thing,'scale') AS scale, 
       sql_variant_property(thing,'maxlength') AS maxlength
FROM cte

Returns

thing                          basetype            precision   scale  maxlength
------------------------------ ------------------- ----------- ------ ---------
1                              int                 10          0      4
1.00                           money               19          4      8
1                              float               53          0      8
1.0000                         numeric             5           4      5
2147483648                     numeric             10          0      5
2011-09-15 01:23:56.123        datetime            23          3      8
2011-09-15 00:00:00.000        datetime            23          3      8
2011-09-15 13:33:41.000        datetime            23          3      8
00000000-0000-0000-0000-000000 uniqueidentifier    0           0      16
Foo                            varchar             0           0      3
Foo                            nvarchar            0           0      6

Leave a Comment