How to insert data in a column in a certain condition

  • So here I would like to insert a value X in a column that `parent_id` conditionally called in the column which is called` sort_order` the value 1 is present.

    Is it possible to do this?:-)

  • guy 1966 (1/7/2016)


    So here I would like to insert a value X in a column that `parent_id` conditionally called in the column which is called` sort_order` the value 1 is present.

    Is it possible to do this?:-)

    Hi

    welcome to SSC forums......probably best way for us to give you a definitive answer, is for you to read

    http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/

    and post back with some relevant data that will assist us and you.

    good luck

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • guy 1966 (1/7/2016)


    So here I would like to insert a value X in a column that `parent_id` conditionally called in the column which is called` sort_order` the value 1 is present.

    Is it possible to do this?:-)

    I believe that you're looking for an UPDATE statement

    It might be as simple as this:

    UPDATE YourTable SET

    parent_id = 0 --Value X

    WHERE sort_order = 1;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I try this :

    UPDATE `categories` SET `parent_id`= 0 [2055] WHERE `sort_order`= 1

    the 2055 is the value to try to applie, but I have error syntax... I use the sql editer on my server to white the code.

    thank!

  • OK , I resolve my error syntax:

    UPDATE `categories` SET `parent_id`= 2055 WHERE `sort_order`= 1

    Thank you so must 😛

  • guy 1966 (1/7/2016)


    I try this :

    UPDATE `categories` SET `parent_id`= 0 [2055] WHERE `sort_order`= 1

    the 2055 is the value to try to applie, but I have error syntax... I use the sql editer on my server to white the code.

    thank!

    Of course you're getting an error. You didn't replace the zero, you just replaced the comment.

    This seems like some RDBMS different from SQL Server. I'm not sure if the quotes and square brackets are needed or might be causing a syntax error as well.

    UPDATE is basic in SQL. You should study how to correctly generate statements with the basic DML (INSERT, UPDATE, DELETE) before implementing any code. It's dangerous and you could get in lots of trouble.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply