Basic update

sql server 2008
I am confused by sql server. I have a table called iso_country_code that was imported from excel.Sql Server has changed the name to iso_country_code$. 
Now I want to update a field and this sql is not working (invalid object name for table name is the error).
UPDATE iso_country_code$
SET Country = 'Afhanistan'
WHERE Name = 'hanistan'
I Have tried the following and still getting the same error. What am I doing wrong?
UPDATE dbo.iso_country_code$
UPDATE [dbo].[iso_country_code$]
UPDATE [dbo].[iso_country_code]
UPDATE iso_country_code
t

There was nothing wrong with the dollar sign.  As rsingh mentioned, the implication here based on the response you gave to the query suggested by Saied is that the table name had additional characters after the dollar sign that were not "visible". 
The next time you run into this situation, try a variation on saied's query:
select '[' + TABLE_NAME + ']' as delimitedname, datalength(TABLE_NAME), len(TABLE_NAME)
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME like '%country%'
order by TABLE_NAME;
While it is good advice to avoid special characters in identifier names, some of the responses have been not particularly illuminating about the root cause.  Some of them have been very misleading.  It isn't particularly helpful to say do this
or don't do that.  If your identifiers do not conform to the regular identifier rules, then you must delimit them in your tsql statements.  That is extra work and it can cause other tools or users problems when they execute statements that assume
your identifiers do conform.  And even if the special character does conform to the regular identifier rules, it is unusual to see them used and it is just simpler/easier to avoid them generally (since there are only 4 that are allowed - and # has a special
meaning as the first character).

Similar Messages

  • Problem with a basic update ..

    i am trying to update a table say tab1 .
    the table tab1 has 3 rows and i want all to be updated .
    the query ...
    UPDATE     tab1
    SET others =(SELECT                              tab2.c FROM tab2 WHERE EXISTS
              (SELECT      1
              FROM     tab3 WHERE                          tab2.id = tab3.id
              ) and map.d='ALL' and rownum < 2)
    but the problem is
    if the inner query finds no data it updates all rows of tab1.others wth null.
    how do i avaoid this ???
    the problem is if even for one case the inner query returns no records even then all records get updated with NULL .
    How to avoid that ??
    Message was edited by:
    SHUBH

    How about this?
    UPDATE MST_ITM_LOC mstitmloc
    SET (primary_source,is_bod_initialized) = (SELECT map.physical_dc_id,'0'
                                               FROM   MST_LOGICAL_TO_DC_MAP map
                                               WHERE EXISTS (SELECT 1
                                                             FROM   MST_CUSTOMER_ROLE mcr,
                                                                    MST_ITEM mstitm
                                                             WHERE  mstitm.is_bod_initialized = 1
                                                             AND    mstitm.sys_ent_state = 'ACTIVE'
                                                             AND    mstitm.item_id = mstitmloc.item_id
                                                             AND    mcr.primary_dc = map.logical_dc_id
                                                             AND    mcr.organization_id = mstitmloc.location_id
                                                             AND    mcr.sys_ent_state = 'ACTIVE'
    WHERE mstitmloc.location_id = i.location_id
    AND EXISTS( SELECT 1
                FROM   MST_LOGICAL_TO_DC_MAP map
                WHERE EXISTS (SELECT 1
                              FROM   MST_CUSTOMER_ROLE mcr,
                                     MST_ITEM mstitm
                              WHERE  mstitm.is_bod_initialized = 1
                              AND    mstitm.sys_ent_state = 'ACTIVE'
                              AND    mstitm.item_id = mstitmloc.item_id
                              AND    mcr.primary_dc = map.logical_dc_id
                              AND    mcr.organization_id = mstitmloc.location_id
                              AND    mcr.sys_ent_state = 'ACTIVE'
              )

  • Basic Update Question

    Dear Group,
    I have two tables in two different R2 databases. We will call them Table1 and Table2 for convenience. I would like to update records in Table2 from the values of rows in Table1.
     I would like to loop through Table1 and find the corresponding record in Table2 and update the fields Table2.PriceChangeDate (datetime) – ‘2014-04-01 00:00:00.000’ and Table2.PriceChange (float) with the value of the Table1.Price (float).
    So to me it would be:
    Update Table2.PriceChangeDate = ‘2014-04-01 00:00:00.000’ AND Table2.PriceChange
     = Table1.Price
    WHERE
    Table2.ProductID  = Table1.ProductID
     AND Table2.PriceLevelID = Table1.PriceLevelID  AND Table2.TimeBand
     = Table2.TimeBand
    The table structure is:
    [Database1].[Table1]:
    ID (nvarchar(15)) - Identity
    ProductID (nvarchar(15))
    PriceLevelID (nvarchar(15))
    TimeBand (nvarchar(15))
    Price (float)
    [Database2].[Table2]:
    ID (nvarchar(15)) - Identity
    ProductID (nvarchar(15))
    PriceLevelID (nvarchar(15))
    TimeBand (nvarchar(15))
    PriceChangeDate (datetime)
    PriceChange (float)
    Thanks very much for your help. It will be easy for the group I am sure but it has me slightly confused.
    Alastair (from UK)

    The one advantage with using MERGE over UPDATE is that the join conditions you causes ambiguity, this will result in error, whereas with UPDATE you will get an indeterministic result.
    The potential ambiguity here is that if one row in the target table matches several rows in the source, this raises the question which price you want to copy. This will not happen if you join on a complete key in the source table, so it may not be a concern
    at all.
    The other advantage with MERGE over this specific form of UPDATE is that MERGE is ANSI-compliant syntax, whereas this form of UPDATE is not. There is another form of UPDATE which is both ANSI-compliant, and which also will raise an error in case of ambiguities:
    Update DB1.dbo.Table1
    SET  PriceChangeDate = '2014-04-01T00:00:00.000'
        ,PriceChange     =
           (SELECT t1.Price
            FROM   DB2.dbo.Table2 AS t2
            WHERE  DB1.dbo.Table1.ProductID = t2.ProductID
              AND  DB1.dbo.Table1.PriceLevelID = t2.PriceLevelID
              AND  DB1.dbo.Table1.TimeBand  = t2.TimeBand)
    WHERE EXISTS (SELECT *
            FROM   DB2.dbo.Table2 AS t2
            WHERE  DB1.dbo.Table1.ProductID = t2.ProductID
              AND  DB1.dbo.Table1.PriceLevelID = t2.PriceLevelID
              AND  DB1.dbo.Table1.TimeBand  = t2.TimeBand)
    But as you see, this model is even more cumbersome than the MERGE statement, and many unexperienced programmers lose themselves in this syntax.
    In practice, most people in the SQL Server world use the syntax that Dan used, and as long as you aware of the risks it incurs, there is no problem with it.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Update after 2 months breaks my squirrelmail / imap authentication

    Ok, updated after 2 months, normally expecting some issues, but nothing this bad.
    Squirrelmail is used for remote hosts to access my server mail over internet.
    This update broke authdaemon I think.
    Here's output of authtest:
    [root@cyclops log]# authtest mark pw(redacted)
    ERR: authdaemon: s_connect() failed: No such file or directory
    Authentication FAILED: No such file or directory
    [root@cyclops log]#
    Which is the same output as in my errors.log when a client tries to access imap. 
    How do I turn verbosity up to get more useful output?
    EDIT:  SOLVED
    Forced REINSTALL of courier-authlib fixed it.  WHY WOULD IT DO THAT?
    That was part of the update I believe, but why would it bork the install on a basic update?
    Last edited by 86turbodsl (2010-04-08 10:19:23)

    Same problem here. For whatever reason, courier-impa is starting authdaemond and also stopping authdaemond directly after running the courier-processes in its init-script.
    I hacked the script a bit, now it's working properly:
    At the top, insert a line
    AUTO_AUTHDAEMON="false"
    Change the first if-clause to read:
    if [ $AUTO_AUTHDAEMON == "true" ] ; then
    and do the same for the second if-clause containing $AUTO_AUTHDAEMON.
    That's it.
    My complete init-script:
    CI_DAEMONS=
    AUTO_AUTHDAEMON="false"
    [ -f /etc/conf.d/courier-imap ] && . /etc/conf.d/courier-imap
    [ -z $AUTO_AUTHDAEMON_LAG ] && AUTO_AUTHDAEMON_LAG=2
    . /etc/rc.conf
    . /etc/rc.d/functions
    case "$1" in
    start)
    if [ $AUTO_AUTHDAEMON == "true" ]; then
    /etc/rc.d/authdaemond start
    sleep ${AUTO_AUTHDAEMON_LAG}
    fi
    if [ ! -f /var/run/daemons/authdaemond ]; then
    echo "ERROR: authdaemond is not running"
    stat_fail
    exit 1
    fi
    for daemon in $CI_DAEMONS; do
    stat_busy "Starting Courier ${daemon}"
    /usr/lib/courier-imap/${daemon}.rc start
    if [ $? -gt 0 ]; then
    stat_fail
    else
    add_daemon $daemon
    stat_done
    fi
    done
    if [ $AUTO_AUTHDAEMON == "true" ]; then
    /etc/rc.d/authdaemond stop
    fi
    stop)
    for daemon in $CI_DAEMONS; do
    stat_busy "Stopping Courier ${daemon}"
    /usr/lib/courier-imap/$daemon.rc stop > /dev/null
    if [ $? -gt 0 ]; then
    stat_fail
    else
    rm_daemon $daemon
    stat_done
    fi
    done
    restart)
    $0 stop
    sleep 1
    $0 start
    echo "usage: $0 {start|stop|restart}"
    esac
    exit 0
    Last edited by mauritzius (2010-04-12 14:52:21)

  • In OSX 10.8, can I use the same apple id to get updates for iPhoto and iMovie?

    Hi, so there are several sites that I work at that have multiple OSX 10.8 devices. I was wondering if there was a way that I can use the same apple ID to update iPhoto or iMovie? Apparently its needed for updates now. Alternatively, is there a way that I can do basic updates with out putting in an apple ID? A few dozen is no problem, but there are more than that which need to be updated. And frankly, its becoming a pain.

    You may only do that on machines you own. Other users must have their own Apple IDs and purchase the software for themselves. If these are enterprises, then contact Apple. They have special programs for enterprise purchasing.

  • After updating to IOS 7, my iphone won't connect to my Itunes

    Alright, this is what's wrong. I have an iphone 4s, which has always been working perfectly, but I decided to update it to the IOS 7 when it became available.
    Once I had updated, which took forever, it seemed to work just fine again although very different from what i was used to. No matter I thought, I'd get used to it.
    Today I then plugged it into my 4 year old macbook (running OS X 10.5.8 and unable to update for some reason) and it said that my iphone couldn't sync with the itunes, that I needed to update to Itunes 1.11 or newer, but - and here's the kicker - the version of Itunes available on the apple site, won't work unless I have operating system OS X 10.6.8 or newer.
    So basically, updating my iphone has made it much worse, has made my expensive macbook fairly useless, at least for updating my phone.
    I'm just thankful that I haven't updated my Ipad yet, now knwoing that it won't work right after the update anyway.
    Any suggestions or ideas as to what I can do? I really don't wanna go out and spend a fortune on a new laptop just so I can sync my itunes.
    Hope someone can help

    I Just found it on the apple site, it arrived on a cd a few days later and worked just fine again.
    i would recommend backing everything up just in case. Better safe than sorry, trust me. I've lost so much when i didnt back up once when re-installing the system.
    IT shoulldnt erase everything, bt it might, so back up just in case
    should you loose everything, then i have some tips on moving stuff fromyour iphone/ipod to the computer

  • Update statement getting ORA-00904 invalid identifier

    I am getting this ORA error when I try to conduct an update statement from a column value in one table to a like-named column in another table.
    For instance, in my select, shown below, this query runs like a champ, returning all of my records
    SELECT
    b.ID,
    b.ZIP, a.ZIP,
    a.NAME,
    a.LOCATION
    FROM TBL_ARCHIVE a
    INNER JOIN TBL_UAT b ON
    a.ID = b.ID
    WHERE
    b.ID > 470000  And b.ID <470100;However, if I try to run an update statement with any of the following, I get this error. It seems so strange to me that I'd get an error using the same columns in the update statement, but would return the desired results effectively from the select statement!
    one version of UPDATE
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;and another
    UPDATE TBL_ARCHIVE
    SET a.ZIP  =
    (SELECT b.ZIP
    FROM TBL_UAT b
    WHERE b.ID <472500 And b.ID >471000)
    FROM TBL_ARCHIVE a
    WHERE a.ID = b.ID)
    WHERE ID IN
    (SELECT ID
    FROM TBL_UAT b
    WHERE b.ID  <472500 And b.ID >471000
    );^ - this one produces a SQL not properly ended. Error ORA-00933: SQL command not properly ended.
    I'm really unsure though, how what I thought was a fairly basic update statement wouldn't work. I'm using Oracle 11g but through either Toad or SQL Plus. I've gotten these same errors in both.
    Though MS Access runs slow as snails, I can manage to run the update statement successfully with it, a thousand records or so at a time. Problem is, I've got about 300K records needing updating.
    I've looked around for similar problems but haven't found one where someone wasn't either using a reserved word for a column, which I'm not, I don't believe, or a problem that really dealt with this error in the context of an update statement.
    But I'd welcome any enlightenment on this.

    rp0428 wrote:
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;That isn't a valid query and neither is the other one.
    Please post the actual query you are using and the actual complete error message you are getting (everything about the error that is displayed).^^
    That is NOT a valid query?
    How else would you have an UPDATE statement created to set the value of a column in table A to the value of a (in this case, same named) column in table B?
    And keep them in order to update the records appropriately?
    I'll append the create statements momentarily.
    Thanks!
    CREATE TABLE TBL_UAT
    ( ID NUMBER(6),
    ZIP VARCHAR2(10 BYTE) ) and
    CREATE TABLE TBL_ARCHIVE
    ( ID NUMBER(6) NOT NULL, NAME VARCHAR2(50 BYTE),
    EMAIL VARCHAR2(50 BYTE),
    LOCATION VARCHAR2(50 BYTE),
    DEPARTMENT VARCHAR2(50 BYTE),
    PRIORITY VARCHAR2(50 BYTE),
    APPROVING_MGR_NAME VARCHAR2(50 BYTE),
    TYPE1 VARCHAR2(50 BYTE),
    TYPE2 VARCHAR2(50 BYTE),
    CONTACT_NAME VARCHAR2(50 BYTE),
    CONTACT_PHN_NO VARCHAR2(50 BYTE),
    LOAN_NUM VARCHAR2(50 BYTE),
    REF_ID VARCHAR2(50 BYTE),
    BORROWER_NAME VARCHAR2(50 BYTE),
    ADDRESS VARCHAR2(50 BYTE),
    CITY VARCHAR2(50 BYTE),
    ST VARCHAR2(50 BYTE),
    ZIP VARCHAR2(10 BYTE),
    SALE_DATE DATE,
    COMMENTS VARCHAR2(800 BYTE),
    TIME_REQ DATE,
    ACCTLOC VARCHAR2(50 BYTE),
    OTHER_ACCTLOC VARCHAR2(50 BYTE)) Hope this can be of assistance.
    Thanks, folks!
    Edited by: user515689 on Feb 7, 2012 11:59 AM

  • The file "iTunes Library.itl" cannot be read because it was created by a newer version of iTunes.  What??? I updated last week I guess and now I cannot open my iTunes.  Please help.

    On 7/27 downloaded 10.4
    before that 7/6 downloaded 10.3.1
    Just basic updates that come through
    Running on MacBook Pro OS X version 10.6.8

    Had same problem and solved it without having to reinstore any music or movies:
    1. Delete old Library file
    2. Go to the 'Previous iTunes Libraries' folder and copy one of the earlier files - note, they have a date extension, e.g. 'iTunes Library 2011-11-01'.
    3. Paste this file in your iTuners folder and rename file by removing the date extension -  'iTunes Library'
    You should have all your music and paylists in tact, unless it was a really old previous file.

  • I have an iPhone 3gs and will be getting a new iPhone 4s. Once I have updated my existing 3gs with iCloud and backed up to my computer, will I be able to transfer my existing data to my new 4s using iCloud or will I need to do this from my iMac.

    I have an iPhone 3gs and will be getting a new iPhone 4s. Once I have updated my existing 3gs with iCloud and backed up to my computer, will I be able to transfer my existing data to my new 4s using iCloud or will I need to do this from my iMac.
    Thanks

    The Apple genius at the Apple store told me this would work. It failed. Basically, updating your iPhone 3GS to iOS5 wipes your 3GS of its data so you can't really do this. Some data worked. Music, photos etc didn't work at all.
    I suggest avoiding iCloud completely for a few weeks until Apple gets it working.

  • How to update Acrobat 9 to current version during CS4 install

    HI All:
    I have a corporate wide deployment of Creative Suite 4 and Acrobat 9 Professional.   Due to the security vulnerabilities of Acrobat Professional, we need to update Acrobat 9 to version 9.4 during the deployment.
    For Acrobat Pro 9 the procedure is to edit the setup.ini to include the patches you want to install.  see the following technote:  http://kb2.adobe.com/cps/507/cpsid_50757.html
    Basically update the setup.ini file
    [Product]
    msi=AcroPro.msi
    Languages=1033;1031;1036
    1033=English (United States)
    1031=German (Germany)
    1036=French (France)
    PATCH=AcroProStdUpd910_T1T2_incr.msp;AcrobatUpd912_all_incr.msp;AcrobatUpd913_all_incr.msp ;AcrobatUpd920_all_incr.msp;AcrobatUpd930_all_incr.msp;AcrobatUpd932_all_incr.msp;AcrobatU pd933_all_incr.msp;AcrobatUpd940_all_incr.msp
    I need to do the same thing with the CS4/Acrobat 9 install but there is no setup.ini file for this install.  I checked the setup.xml but can not find a way to do this.
    Does anyone have any information on how to do this?
    thank you,

    I have found that I can update CS4 Acrobat to the current version using a batch file.
    I have created the batch file calling Acrobat *.msp files and there was no other commands needed to run MSIEXEC.  I have tested it and it runs and starts the installer.  
    Contents of batch file:
    @ECHO OFF
    ::  Acrobat Professional 9.0 auto update for CS4
    ::  Updates Acrobat 9.0 Professional to Version 9.4.1
    ::  David Chamberlin
    ::  December 9, 2010
    ::  rev 3.0
    msiexec /p "[path]\AcroProStdUpd910_T1T2_incr.msp;[path]\AcrobatUpd912_all_incr.msp;[path]\AcrobatUp d913_all_incr.msp;[path]\AcrobatUpd920_all_incr.msp;[path]\AcrobatUpd930_all_incr.msp;[pat h]\AcrobatUpd932_all_incr.msp;[path]\AcrobatUpd933_all_incr.msp;[path]\AcrobatUpd940_all_i ncr.msp;[path]\AcrobatUpd941_all_incr.msp" REINSTALLMODE=omus REINSTALL=ALL /q

  • How do I add/update/delete data using ColdFusion Builder 3?

    I feel like this is a really simple and stupid question and should be easy to figure out, but I can't.
    I am relearning ColdFusion after 12 years out of the IT field.  I am using the ColdFusion 9 Getting Started:Volume 1 book.  In Chapter 7 it states that I need to edit the Application.cfc file so that I can edit the database rather than just selecting from the database.  I can't seem to find anything related to that file in any search.  In my ColdFusion 11 Administrator I have set this mySQL database to be able to be edited, but ColdFusion Builder 3 doesn't seem to allow any editing of the tables.  I have not had much luck searching for help regarding this on the internet either.  My biggest problem so far is getting ColdFusion Builder to talk with my mySQL database properly so I can actually get on with relearning ColdFusion and writing code.  Frustrating!!

    I do have ColdFusion 11 Administrator installed.  When I go to Data and Services there and open the datasource (OWS) that I want to connect to and query off of, and go to Advanced Settings, I show that the following are selected:
    SELECT
    CREATE
    GRANT
    INSERT
    DROP
    REVOKE
    UPDATE
    ALTER
    Stored Procedures
    DELETE
    If, in ColdFusion Builder 3, I open the RDS Query viewer and write the following basic update query (Server: default:local; Datasource: OWS):
    insert into directors(FirstName, LastName)
    Values ('Benjamin', 'Forta');
    I get the following RDS error message:
    java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
    According to the book and some information I have seen online, the SQL Query Tool, for security's sake, by default allows execution of SELECT statements, but no other SQL statements.  According to the book, to change this behavior I need to edit the Application.cfc file in the ows/sql directory.  I have to change the THIS.select_only flag from the default of yes to no and save the file.  I cannot find this file anywhere.  I have seen an application.cfm, but I think this is different that what they want because I can't find anything in that file that says THIS.select.

  • Update records in huge table

    Hi,
    I need to update two fields in a huge table (> 200.000.000 records). I've created 2 basic update scripts with a where clause. The problem is that there isn't an index on these fields in the where clause. How can I solve this? Creating a new index is not an option.
    An other solution is to update the whole table (so without a where clause) but I don't know if it takes a lot of time, locks records,...
    Any suggestions?
    Thanks.
    Ken

    Ken,
    You may be better off reading the metalink documents. PDML stands for Parallel DML. You can use parallel slaves to get the update done quickly. Obviously this is dependent on the number of parallel slaves you have and the degree you set
    Type PDML on metalink
    G

  • SQL Query updateable report with row selector. Update process.

    I have a SQL Query updateable report with the row selector(s).
    How would I identify the row selector in an update process on the page.
    I would like to update certain columns to a value of a select box on the page.
    Using the basic:
    UPDATE table_name
    SET column1=value
    WHERE some_column=some_value
    I would need to do:
    UPDATE table_name
    SET column1= :P1_select
    WHERE [row selector] = ?
    Now sure how to identify the [row selector] and/or validate it is checked.
    Thanks,
    Bob

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • Updating a table using a to_char date

    Dear all;
    I have the following query and table below
    create table t1
           cid varchar2(200),
           yearid varchar2(200),
           begin_date date
    insert into t1
               (cid, yearid, begin_date)
             values
               ('A', '2010_1', sysdate);
      insert into t1
               (cid, yearid, begin_date)
             values
               ('B', '2010_1', to_date('03/04/2011', 'MM/DD/YYYY'));
    insert into t1
               (cid, yearid, begin_date)
             values
               ('C', '2010_1', to_date('01/02/2011', 'MM/DD/YYYY'));and I have this update statement below
       update t1 t
           set t.yearid = '2011_1'
           where to_char(t.begin_date, 'YYYY') = substr(t.yearid, 1, 4);what i am trying to is basically update table t1 yearid which is a varchar2 where it has to_char begin date that are irregular...so in my sample case,
    to_char of the begin date return a 2011
    hence, the yearid should be 2011_1 instead.
    However, my udate statement isnt working though

    Hi,
    user13328581 wrote:
    Dear all;
    I have the following query and table below
    create table t1
    cid varchar2(200),
    yearid varchar2(200),
    begin_date date
    insert into t1
    (cid, yearid, begin_date)
    values
    ('A', '2010_1', sysdate);
    insert into t1
    (cid, yearid, begin_date)
    values
    ('B', '2010_1', to_date('03/04/2011', 'MM/DD/YYYY'));
    insert into t1
    (cid, yearid, begin_date)
    values
    ('C', '2010_1', to_date('01/02/2011', 'MM/DD/YYYY'));and I have this update statement below
    update t1 t
    set t.yearid = '2011_1'
    where to_char(t.begin_date, 'YYYY') = substr(t.yearid, 1, 4);what i am trying to is basically update table t1 yearid which is a varchar2 where it has to_char begin date that are irregular...so in my sample case,
    to_char of the begin date return a 2011
    hence, the yearid should be 2011_1 instead.
    However, my udate statement isnt working thoughWhat's wrong with it?
    What are the results you want to get (that is, what should the table contain after the UPDATE? Post what you would like to see as the results of "SELECT * FROM t1" after the UPDATE.)
    Point out where the UPDATE statement you posted is producing the wrong results.
    Is it changing the wrong rows? Maybe the WHERE clause is wrong. Maybe you meant != instead of =.

  • How to update sales of last 3 months only

    I have a query which basically updates the sales for the whole year, but i just want that one to be changed such that it only updates for the past 3 months,irrespective
    of the year ( i mean to say if i run it today it must update march,april,may of 2014 but if i run it on jan 2015 then it must update oct,nov,dec of 2014).
    Below is my update statement
    update tODS_GLBalance
    set tODS_GLBalance.tUTL_JobLogging_Key = @tUTL_JobLogging_Key,
    tODS_GLBalance.Balance = vODS_GLBalance.GLAmount,
    tODS_GLBalance.ModifiedDate = GETDATE(),
    tODS_GLBalance.ModifiedUser = SUSER_NAME()
    From ODS.Staging.vODS_GLBalance
    Left Outer Join Ods.JJill.tODS_GLBalance
    ON tODS_GLBalance.FiscalYearId = vODS_GLBalance.FiscalYearId
    AND tODS_GLBalance.FiscalMonthOfYearId = vODS_GLBalance.FiscalMonthOfYearId
    AND tODS_GLBalance.Page = vODS_GLBalance.PAGE
    Where
    tODS_GLBalance.FiscalYearId = YEAR(GETDATE())
    AND
    tODS_GLBalance.FiscalMonthOfYearId = vODS_GLBalance.FiscalMonthOfYearId
    AND tODS_GLBalance.FiscalYearId = vODS_GLBalance.FiscalYearId
    AND tODS_GLBalance.Page = vODS_GLBalance.Page
    AND tODS_GLBalance.Balance <> vODS_GLBalance.GLAmount
    Can someone please help me with this, Please let me know if you have any questions or if i am unclear.
    Thanks

    I suggest adding this line of code to the where clause:
    AND
    tODS_GLBalance.FiscalMonthOfYearId
    in(month(dateadd(m,-1,getdate())),month(dateadd(m,-2,getdate())),month(dateadd(m,-3,getdate())))
    This assumes that you are testing against the fiscalmonthofyear and that the fiscal periods are the same as calendar periods. Otherwise, there will be some adjusting to do.
    This is basically checking to see if the fiscal monthofyearid is in the 3 most recent months.
    /* If this helps, please click appropriately below. Thank you! */

Maybe you are looking for