I am using sql and sql-server
I have created a new column in a view with a case. The problem is the following: I believe that the newly created column has a default datatype.
My question is how do i define the datatype of a new column when creating it? I have tried using convert and cast.
ALTER VIEW [dbo].[vtbl_dim_vb]
AS
SELECT
vb_key,ver_login,
ver_name,
ver_klass_descr,
CAST(ver_klass AS varchar(40)) + ' ' + ver_klass_descr AS klass_descr_d,
store_code,
store_name,
CASE WHEN LEFT(ver_klass, 1) = 'S' THEN ver_klass ELSE NULL END AS ver_sector,
CASE WHEN LEFT(ver_klass, 1) = 'M' THEN ver_klass ELSE NULL END AS ver_metier,
CASE WHEN LEFT(ver_klass, 1) <> 'S' AND LEFT(ver_klass, 1) <> 'M' THEN ver_klass ELSE NULL END AS ver_rayon
FROM
dbo.tbl_dim_vb
I have tried to use the cast command but that didn’t work:
CAST ( expression AS data_type [ ( length ) ] )
I want to know what options i have for the third case.
this is how the code looks like that I tried:
CASE WHEN LEFT(ver_klass, 1) <> 'S' AND LEFT(ver_klass, 1) <> 'M' THEN ver_klass ELSE NULL END AS CAST ( ver_rayon AS int(10) )
I need the newly created column ver_rayon to be an integer datatype.
Thanks a lot for any advice ; )
Maybe something like this: