none
Update SQL statement failing when using != or In RRS feed

  • Question

  • Contactname is varchar(1000)

    UPDATE customers
    SET ContactName='Statecode !='MA''
    WHERE CustomerID=1;

    Update SQL statement failing when using !=

    UPDATE plan
    SET planname =product in('1'.'2')
    WHERE planID=1;

    Update SQL statement failing when using IN 

    Any ideas?



    • Edited by Michael3188 Wednesday, June 19, 2019 9:04 PM
    Wednesday, June 19, 2019 4:17 PM

Answers

  • I was able to solve.

    I have already posted my error message 

    UPDATE customers
    SET ContactName='Statecode !='MA''
    WHERE CustomerID=1;

    errors: Update SQL statement failing when using !=

    UPDATE plan
    SET planname =product in('1'.'2')
    WHERE planID=1;

    Error; Update SQL statement failing when using IN 

    column values I am giving is something like a free form text not connected to any column in the table. I just wanted to update column value in table  for customerID =1

    This is the solution

    UPDATE customers
    SET ContactName='Statecode !=''MA'' '
    WHERE CustomerID=1;


    UPDATE plan
    SET planname ='product in(''1''.''2'')'
    WHERE planID=1;

    • Marked as answer by Michael3188 Wednesday, June 19, 2019 9:03 PM
    Wednesday, June 19, 2019 9:03 PM

All replies

  • Those are not valid tsql statements. Not certain what you are trying to do with either, but including "Urgent" in your title or description does not make anyone else more inclined to help more quickly.  

    Your first update statement makes no sense. What name to you want to use when setting the ContactName column for rows that have CustomerID = 1? I doubt you intend to set it to anything similar to what you posted. Rather I would expect to see something like: 

    ... SET ContactName = 'Bob Smith' ...

    Perhaps you only want to update those customers where the StateCode column is not 'MA'? But what value do you want to apply to ContactName? Are you attempting to "look up" a name in another table? 

    The same sort of questions apply to your second update statement. And for future reference, you should always identify the version and edition of sql server you are using. You should also include the complete text of any error messages you encounter - no one should need to ask or guess. 

    Wednesday, June 19, 2019 6:25 PM
  • I was able to solve.

    I have already posted my error message 

    UPDATE customers
    SET ContactName='Statecode !='MA''
    WHERE CustomerID=1;

    errors: Update SQL statement failing when using !=

    UPDATE plan
    SET planname =product in('1'.'2')
    WHERE planID=1;

    Error; Update SQL statement failing when using IN 

    column values I am giving is something like a free form text not connected to any column in the table. I just wanted to update column value in table  for customerID =1

    This is the solution

    UPDATE customers
    SET ContactName='Statecode !=''MA'' '
    WHERE CustomerID=1;


    UPDATE plan
    SET planname ='product in(''1''.''2'')'
    WHERE planID=1;

    • Marked as answer by Michael3188 Wednesday, June 19, 2019 9:03 PM
    Wednesday, June 19, 2019 9:03 PM