English 中文(简体)
具有多种条件的最新表格
原标题:update table with multiple conditions
  • 时间:2011-10-08 01:44:54
  •  标签:
  • sql
  • tsql

I have table as follows:

SYS_ID  SUB_NET_ID  NODE_NAME   NODE_ID NODE_EQ_NO  NODE_VAR_NO TEMP_ID EQUIP_TYPE  EQ_ID   VAR_ID  VAR_OBJECT  VAR_NAME    VAR_SUBSET  VAR_SET CALC_VAR_TYPE   DATA_TYPE   DOF
15  1   BLEND   1   13  21  16      5   0   BLEND   DEMAND  SELF    BLEND_OUT   VAR CONTINOUS                  
15  1   BLEND   1   14  6   16      6   0   BLEND   DEMAND  BLEND   BLEND   VAR CONTINOUS                  
15  1   DEST    2   5   2   4       7   0   DEST    DEMAND  SELF    DEST_IN VAR CONTINOUS                  
15  1   DEST    2   1   3   4       1   0   DEST    DEMAND  UNDEF   DEST_IN VAR CONTINOUS                  
15  1   DEST    2   4   6   4       4   0   DEST    MFLOW   SELF    DEST_IN VAR CONTINOUS                  
15  1   SALK    5   6   5   13      4   0   SALK    MFLOW   SELF    SALK_OUT    VAR binary                 
15  1   SPEN    7   8   4   13      6   0   SPEN    MFLOW   SELF    SPEN_OUT    VAR integer    

I want to update the column data_type to 1 where data_type is continous and update to 0 where it is binary and so on... any suggestion

最佳回答

使用CASE 声明:

UPDATE my_tbl SET data_type =
 CASE data_type
   WHEN  continous  THEN  0 
   WHEN  binary     THEN  1 
   -- more options
   ELSE data_type  -- to retain original string if no substitute is listed
 END;

你们知道,数据类型仍然不是数字,而是以前哪类数据是正确的?

问题回答

暂无回答




相关问题
How to write this T-SQL WHERE condition?

I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...

Customer and Order Sql Statement

TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...

Recommended way of querying multiple Versioned tables

Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...

update duplicate record

I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...

Define variable to use with IN operator (T-SQL)

I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签