ceefax12
ceefax12

Reputation: 181

Conditional If statement within table visual basic database (T-SQL)

I would like to create a column that displays if a student has passed or failed. To pass the overall grade needs to be above 40.

I have done this before using access using the following:

IIf([Overall]<=40,"fail","pass")

But I’m very new to visual basic. Anyone got any ideas on how I can do this?

The IDE I am using is Visual Studio

This is the table

enter image description here

Or if there are any tutorials that you would recommend that would be great.

Upvotes: 2

Views: 361

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

You can do it in your table definition:

  • You can use a CASE WHEN statement to check for a criteria and provide a value.
  • You can not refer to a computed column in another computed column.

So you can add a column like this:

[ColumnName] AS CASE WHEN (the formula for overall) <= 40 THEN 'fail' ELSE 'pass' END

Also you can make the result as a bit (boolean) data type and let the application decide to show a string instead of true or false.

Upvotes: 3

Related Questions