#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0

    MySQL query to SQL server query


    Can you help me with the following? I’ve to change MySQL queries to SQL Server queries.

    The original query is:
    INSERT INTO codebook(SELECT tableid, name, tablename, NULL, IF(modify=0,'y','n'), 'y' FROM commontables)

    I change it into
    1.
    INSERT INTO codebook( codelistid, name, tablename, parentid, special, active)
    SELECT tableid, name, tablename, NULL, 'IF(modify=0,'y','n')', 'y'
    FROM commontables
    Not good: Line 2: Incorrect syntax near ','
    2.
    INSERT INTO codebook( codelistid, name, tablename, parentid, special, active)
    SELECT tableid, name, tablename, NULL, modify , 'y'
    FROM commontables
    WHERE special= 'IF(modify=0,''y'',''n'')'
    Again: Invalid column name 'special'

    May be the problem is in type “special” is char(1), “modify” int(4)?Not good: Again:
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,376
    Rep Power
    391
    Code:
    INSERT INTO codebook( codelistid, name, tablename, parentid, special, active) 
    
    SELECT tableid, name, tablename, NULL, 
    case when modify=0 then 'y' else 'n' end, 'y' FROM commontables

IMN logo majestic logo threadwatch logo seochat tools logo