Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:33:12+00:00 2026-06-02T14:33:12+00:00

I am using sql and sql-server I have created a new column in a

  • 0

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 ; )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:33:15+00:00Added an answer on June 2, 2026 at 2:33 pm

    Maybe something like this:

    CAST(
    (
      CASE 
      WHEN LEFT(ver_klass, 1) <> 'S' AND LEFT(ver_klass, 1) <> 'M' 
      THEN ver_klass 
      ELSE NULL 
      END
    ) AS INT)
    AS ver_rayon
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I have created using SQL Server Developer 2008. I
I am using SQL Server 2008 Enterprise. I have created a very simple test
I'm using SQL Server 2005 and have the following T-SQL statement: DECLARE @MP VARCHAR(500)
Using Microsoft SQL server 2008 I have a query that is in need of
I have created CustomerTbl in SQL Server 2008. For that i have, Right Clicking
I have File-Stream enabled database. I have created table with column that has the
[using SQL Server 2005] I have a table full of users, I want to
Using MS SQL Server .I have made a Stored Procedure named SP_Get_CallsLogged . I
I'm using SQL Server 2005 I have a user. We'll call him User1. He
I'm using SQL Server 2008 R2 and Microsoft Excel. I have the server set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.