SELECT question

  • Thread starter Thread starter Guy Cohen
  • Start date Start date
G

Guy Cohen

Hi all
I have a table with a bit column
I want to populate this table to a grid.
Instead of True/False I want to display "On time" or "Later"
How do I write the SQL query so it will replace True with "On time" and
False with "Later"

TIA
Guy
 
Hi all
I have a table with a bit column
I want to populate this table to a grid.
Instead of True/False I want to display "On time" or "Later"
How do I write the SQL query so it will replace True with "On time" and
False with "Later"

Several ways of doing this.

1) Don't do it in SQL at all. Instead, do it on the GridView's RowDataBound
method

protected void gvGigs_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Text = (e.Row.Cells[0].Text == "True" ? "On time" :
"Later");
}

2) Do it in T-SQL, using the CASE WHEN statement e.g.

SELECT
CASE <bit field>
WHEN 1 THEN 'On time'
ELSE 'Later'
END AS <column name>
FROM <table>
 
Back
Top