0

I have a column 'Value' of sql_variant type. It has the value

'Device Warning: Bus Transient, Warning Code: 164, Timestamp: 2015-12-23 13:02:48.750'

If I try to select

TRY_CAST([Value] AS nvarchar) as varvalue

I get the value

Device Warning: Bus Transient,

How can we cast a sql_variant type without losing some data? I needed to convert it into a nvarchar because I need to use a SUBSTING function to extract parts of the value.

Any help would be greatly appreciated!!!

Aparna
  • 835
  • 2
  • 23
  • 47
  • 2
    well, just try giving an actual length to your `nvarchar`: `TRY_CAST([Value] AS nvarchar(2000)) as varvalue` – Lamak Aug 04 '16 at 14:41

1 Answers1

1

nchar and nvarchar (Transact-SQL)

Remarks
When n is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified with the CAST function, the default length is 30.

1> select len('Device Warning: Bus Transient,')
2> go

-----------
         30

Specify a length.

QED

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569