Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To generate a column with categories using two numerical columns in SQL Server, follow these steps:

  1. Determine the categories: Decide on the categories you want to use to group the data in your two numerical columns. For example, you may want to group them into "low," "medium," and "high" categories based on their relative values.

  2. Create a CASE statement: Use a CASE statement to create a new column that assigns each row a category based on the values in your two numerical columns. For example:

SELECT column1, column2, 
CASE 
  WHEN column1 + column2 < 10 THEN 'low'
  WHEN column1 + column2 >= 10 AND column1 + column2 < 20 THEN 'medium'
  WHEN column1 + column2 >= 20 THEN 'high'
END as category
FROM your_table;

In this example, we are creating a new column called "category" that assigns each row a category based on the sum of the values in column1 and column2.

  1. Run the query: Once you've created your CASE statement, run the query to generate a new column with categories based on your two numerical columns.