Home Forums SQL Server 2008 T-SQL (SS2K8) How to update a field with the same Value within a Range using SQL? RE: How to update a field with the same Value within a Range using SQL?

  • It's easy to convert a SELECT into an UPDATE.

    You have 2 options depending on the complexity of the UPDATE. You can keep the FROM and use a table alias in the UPDATE.

    UPDATE t SET

    ExpiryDate = '20160630'

    from mytable t

    where AccNumber between 1 and 500;

    Or you could remove the FROM clause

    UPDATE mytable SET

    ExpiryDate = '20160630'

    where AccNumber between 1 and 500;

    Note that:

    - I added a semicolon which is optional but might not be that way in the future (it isn't for certain statements).

    - I removed the quotes to handle the values as integers.

    - I'm using the ISO format for dates which is not dependent on any settings, unlike most other formats.

    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