Sql Server bulk update

Hi
I have a datatable (in .net Application) which has a huge data.
I need to update/insert the data in to  the Sql server database table.
 (Upadte if the data exist in the table and insert if the data does not exist in the table).
just I wanted to know Is there any option for bulk insert or update rather than checking each row in (using cursor - SP) the table and inserting/updating..
Samproo

Hi Samproo, You will never use a cursor to check the existence of a record to whether update it or insert it. It will cost a lot to you when huge data stars flowing in.
Just use the Exists statement as below.
IF EXISTS(SELECT 1 FROM Table_Name WHERE condition = Value)
BEGIN
......UPDATE DATA Statemet.....
END
ELSE
BEGIN
.......INSERT DATA Statement.......
END
And Yes, you can use this inside any stored procedure the same way it is.
or if you doing matches between two tables then you can use MERGE as well...
Please mark as answer, if this has helped you solve the issue.
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Similar Messages

  • SQL Server 2005 Update mechanism problem

    Hi Gurus,
          We're faced with one SQL Server 2005 update mechanism problem. Here is my problem:
          According to our requirement, an add_on interface program is designed to execute creation of production order by calling Bapi.
          There are 3 steps in this add_on program:
          Step 1: Create production order
          Step 2: Change the information of production.
          Step 3: Some other
          After the step 1 has finished immediately step 2 is called, Howerver the information which should have inserted into database table couldn't be found from database. (Maybe because the time between two steps is too short to finish inserting)
          In order to ensure the complete of the transaction, before the step 2 executed, the information in step 1 should have inserted into database.
           Is there any solution to solve this problem?
           I guess whether there is any parameter which control the time of writing buffer into database...
    Any advice is appreciated.
    Thanks & Best Regards,
    Derek Yang

    Hi
    I have the same problem, but that post didnt help me
    This is the error I have:
    My snapshot agent hangs.. waiting for a response from the server.. and timeouts.
    This only hapens for a publication that has a filter based on HOSTNAME()
    The other publications work fine
    Error messages:
    Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Command Text: sp_MSsetup_partition_groups
    Parameters: @publication = XXXXXXX
    Stack: at Microsoft.SqlServer.Replication.AgentCore.ReMapSqlException(SqlException e, SqlCommand command)
    at Microsoft.SqlServer.Replication.AgentCore.AgentExecuteNonQuery(SqlCommand command, Int32 queryTimeout)
    at Microsoft.SqlServer.Replication.AgentCore.ExecuteDiscardResults(CommandSetupDelegate commandSetupDelegate, Int32 queryTimeout)
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.SetupPartitionGroups()
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.DoRegularMergeSnapshotPreparations()
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.DoPreArticleFilesGenerationProcessing()
    at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.GenerateSnapshot()
    at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.InternalRun()
    at Microsoft.SqlServer.Replication.AgentCore.Run() (Source: MSSQLServer, Error number: -2)
    Get help: http://help/-2
    Server XXXXXXXXX, Level 11, State 0, Procedure , Line 0
    Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. (Source: MSSQLServer, Error number: -2)
    Get help: http://help/-2

  • MS SQL Server 2012 Updates via SCCM 2012 R2

    I'm trying to determine if SCCM 2012 R2 can manage and deploy Hotfixes, Updates and Service packs for SQL Server 2012. Can someone please confirm that SCCM can manage this, how to download SQL Server Hotfixes, Updates and Service Packs into SCCM and where
    I can find instructions on setting up my MS SQL Server computers to receive SQL updates from SCCM.
    Thanks. 

    ConfigMgr absolutely can deploy updates and service packs for SQL. You just need to choose the versions you want in Software Update Point Products and Classifications. It's no different than deploying any other Microsoft updates.
    http://www.gerryhampsoncm.blogspot.ie/2013/04/sccm-2012-sp1-step-by-step-guide-part.html
    Is it a good idea? I don't think so. I think SQL updates should be part of a carefully planned (and tested) manual upgrade.
    Gerry Hampson | Blog:
    www.gerryhampsoncm.blogspot.ie | LinkedIn:
    Gerry Hampson | Twitter:
    @gerryhampson

  • SQL SERVER BULK FETCH AND INSERT/UPDATE?

    Hi All,
           I am currently working with C and SQL Server 2012. My requirement is to Bulk fetch the records and Insert/Update the same in the other table with some  business logic?
           How do i do this?
           Thanks in Advance.
    Regards
    Yogesh.B

    > is there a possibility that I can do a bulk fetch and place it in an array, even inside a stored procedure ?
    You can use Temporary tables or Table variables and have them indexes as well
    >After I have processed my records, tell me a way that I will NOT go, RECORD by RECORD basis, even inside a stored procedure ?
    As i said earlier, you can perform UPDATE these temporary tables or table variables and finally INSERT/ UPDATE your base table
    >Arrays are used just to minimize the traffic between the server and the program area. They are used for efficient processing.
    In your case you will first have to populate the array (Using some of your queries from the server) which means you will first load the arrary, do some updates, and then send them back to server therefore
    network engagement
    So I just gave you some thoughts I feel could be useful for your implementation, like we say, there are many ways so pick the one that works good for you in the long run with good scalability
    Good Luck! Please Mark This As Answer if it solved your issue. Please Vote This As Helpful if it helps to solve your issue

  • Sql server bulk insert blob filename parameter

    My problem SQL script:
    declare @filepath varchar(100)
    set @filepath = 'E:\foto\1.jpg'
    INSERT INTO [dbo].[MsQuestions] ([TestCategoryID], [LevelID], [TestTypeID], [QuestionText], [QuestionImg])
    select  1 , 1, 8, 'data gambar',BulkColumn FROM OPENROWSET(BULK   @filepath , SINGLE_BLOB)
    thanks.
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%
    string sConn = @"server=.; database=OnlineTesting; Integrated Security=True";
    SqlConnection objConn = new SqlConnection(sConn);
    objConn.Open();
    string sTSQL = "exec sp_filenamea";
    SqlCommand objCmd = new SqlCommand(sTSQL, objConn);
    objCmd.CommandType = CommandType.Text;
    SqlDataReader dr = objCmd.ExecuteReader();
    dr.Read();
    Response.BinaryWrite((byte[])dr["QuestionImg"]);
    objConn.Close();
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <title>Exec SP</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
    </body>
    </html>

    Perhaps this 
    http://dimantdatabasesolutions.blogspot.co.il/2009/05/how-to-uploadmodify-more-than-one-blob.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • SQL SERVER SECURITY Update KB2977321 and KB2716436 Error Code 1642

    I had gone through some of the related question that has been shared over here but since for me there was a definite Error Pop up stating
    SQL SERVER SET UP FAILER "NT Service Unable to start MSSQLSERVER" but i noticed that after each of the update the version had changed and the database is running normally, just want to confirm if the updates are working fine or some
    other measures has to be taken.
    I Ran the discovery report and it shows the latest version
    Can i take this as a successfull installation and no issues will occur?
    Please suggest.

    I have pulled this from the Setup Bootstrap log. IN the Administrative log in the event viewer there is nothing helpful.
    2015-03-31 15:07:22 Slp: Sco: Attempting to open service handle for service MSSQLSERVER
    2015-03-31 15:07:22 Slp: Invoking QueryServiceStatusEx Win32 API
    2015-03-31 15:07:22 Slp: Sco: Attempting to close service handle for service MSSQLSERVER
    2015-03-31 15:07:22 Slp: Sco: Attempting to close SC Manager
    2015-03-31 15:07:22 Slp: Sco: Returning service process id 5644
    2015-03-31 15:07:22 Slp: Waiting for nt event Global\sqlserverRecComplete to be created
    2015-03-31 15:07:22 Slp: Waiting for nt event Global\sqlserverRecComplete or sql process handle to be signaled
    2015-03-31 15:07:22 Slp: Error: Failed to start the following NT service after patch action: MSSQLSERVER
    2015-03-31 15:07:22 Slp: Sleeping 10 seconds before retrying NT service start request
    2015-03-31 15:07:32 Slp: Sco: Attempting to start service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to start service MSSQLSERVER, start parameters
    2015-03-31 15:07:32 Slp: Sco: Attempting to start service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to open SC Manager
    2015-03-31 15:07:32 Slp: Sco: Attempting to open service handle for service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Service MSSQLSERVER already running or pending start
    2015-03-31 15:07:32 Slp: Sco: Attempting to close service handle for service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to close SC Manager
    2015-03-31 15:07:32 Slp: Waiting for the following Sql NT service to indicate successful startup: MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to get service process id for service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to open SC Manager
    2015-03-31 15:07:32 Slp: Sco: Attempting to open service handle for service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Invoking QueryServiceStatusEx Win32 API
    2015-03-31 15:07:32 Slp: Sco: Attempting to close service handle for service MSSQLSERVER
    2015-03-31 15:07:32 Slp: Sco: Attempting to close SC Manager
    2015-03-31 15:07:32 Slp: Sco: Returning service process id 5644
    2015-03-31 15:07:32 Slp: Waiting for nt event Global\sqlserverRecComplete to be created
    2015-03-31 15:07:32 Slp: Waiting for nt event Global\sqlserverRecComplete or sql process handle to be signaled
    2015-03-31 15:07:32 Slp: Error: Failed to start the following NT service after patch action: MSSQLSERVER
    2015-03-31 15:07:32 Slp: Error: Action "StartPatchedServices" threw an exception during execution.
    2015-03-31 15:07:32 Slp: Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException: The NT service 'MSSQLSERVER' could not be started. ---> Microsoft.SqlServer.Chainer.Infrastructure.ChainerInvalidOperationException: The NT service 'MSSQLSERVER'
    could not be started.
    2015-03-31 15:07:32 Slp:    at Microsoft.SqlServer.Configuration.SetupExtension.StartPatchedServicesAction.ExecuteAction(String actionId)
    2015-03-31 15:07:32 Slp:    at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
    2015-03-31 15:07:32 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.InvokeAction(WorkflowObject metabase, TextWriter statusStream)
    2015-03-31 15:07:32 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.PendingActions.InvokeActions(WorkflowObject metaDb, TextWriter loggingStream)
    2015-03-31 15:07:32 Slp:    --- End of inner exception stack trace ---
    2015-03-31 15:07:32 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.PendingActions.InvokeActions(WorkflowObject metaDb, TextWriter loggingStream)
    2015-03-31 15:07:36 Slp: Received request to add the following file to Watson reporting: C:\Users\imchenatadmin\AppData\Local\Temp\2\tmp4C5D.tmp
    2015-03-31 15:07:36 Slp: The following is an exception stack listing the exceptions in outermost to innermost order
    2015-03-31 15:07:36 Slp: Inner exceptions are being indented
    2015-03-31 15:07:36 Slp:
    2015-03-31 15:07:36 Slp: Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInvalidOperationException
    2015-03-31 15:07:36 Slp:     Message:
    2015-03-31 15:07:36 Slp:         The NT service 'MSSQLSERVER' could not be started.
    2015-03-31 15:07:36 Slp:     Stack:
    2015-03-31 15:07:36 Slp:         at Microsoft.SqlServer.Configuration.SetupExtension.StartPatchedServicesAction.ExecuteAction(String actionId)
    2015-03-31 15:07:36 Slp:         at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
    2015-03-31 15:07:36 Slp:         at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.InvokeAction(WorkflowObject metabase, TextWriter statusStream)
    2015-03-31 15:07:36 Slp:         at Microsoft.SqlServer.Setup.Chainer.Workflow.PendingActions.InvokeActions(WorkflowObject metaDb, TextWriter loggingStream)
    2015-03-31 15:07:36 Slp: Watson Bucket 1
     Original Parameter Values
    2015-03-31 15:07:36 Slp: Parameter 0 : SQL2008@RTM@KB2977321
    2015-03-31 15:07:36 Slp: Parameter 1 : Microsoft.SqlServer.Configuration.SetupExtension.StartPatchedServicesAction.ExecuteAction
    2015-03-31 15:07:36 Slp: Parameter 2 : Microsoft.SqlServer.Configuration.SetupExtension.StartPatchedServicesAction.ExecuteAction
    2015-03-31 15:07:36 Slp: Parameter 3 : Microsoft.SqlServer.Chainer.Infrastructure.ChainerInvalidOperationException@1202@1
    2015-03-31 15:07:36 Slp: Parameter 4 : Microsoft.SqlServer.Chainer.Infrastructure.ChainerInvalidOperationException@1202@1
    2015-03-31 15:07:36 Slp: Parameter 5 : StartPatchedServices
    2015-03-31 15:07:36 Slp:
     Final Parameter Values
    2015-03-31 15:07:36 Slp: Parameter 0 : SQL2008@RTM@KB2977321
    2015-03-31 15:07:36 Slp: Parameter 1 : 0x0EE19F0D
    2015-03-31 15:07:36 Slp: Parameter 2 : 0x0EE19F0D
    2015-03-31 15:07:36 Slp: Parameter 3 : 0xF762992B@1202@1
    2015-03-31 15:07:36 Slp: Parameter 4 : 0xF762992B@1202@1
    2015-03-31 15:07:36 Slp: Parameter 5 : StartPatchedServices
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Microsoft_Windows_CurrentVersion_Uninstall.reg_
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\MSSQLServer to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Microsoft_MSSQLServer.reg_
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Wow6432Node_Microsoft_Microsoft
    SQL Server.reg_
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Wow6432Node_Microsoft_Windows_CurrentVersion_Uninstall.reg_
    2015-03-31 15:07:37 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Wow6432Node\Microsoft\MSSQLServer to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20150331_145638\MSSQLSERVER\Registry_SOFTWARE_Wow6432Node_Microsoft_MSSQLServer.reg_
    2015-03-31 15:07:40 Slp: The NT service 'MSSQLSERVER' could not be started.
    2015-03-31 15:07:40 Slp: Watson bucket for exception based failure has been created
    2015-03-31 15:07:40 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
    2015-03-31 15:07:40 Slp: Sco: Attempting to open registry subkey
    2015-03-31 15:07:40 Slp: Sco: Attempting to open registry subkey Software\Microsoft\PCHealth\ErrorReporting\DW\Installed
    2015-03-31 15:07:40 Slp: Sco: Attempting to get registry value DW0201
    2015-03-31 15:07:40 Slp: Submitted 1 of 1 failures to the Watson data repository
    2015-03-31 15:07:43 Slp:
    2015-03-31 15:07:43 Slp: ----------------------------------------------------------------------
    2015-03-31 15:07:43 Slp:
    2015-03-31 15:07:43 Slp: Error result: -2068709375
    2015-03-31 15:07:43 Slp: Result facility code: 1202
    2015-03-31 15:07:43 Slp: Result error code: 1

  • MS-SQL Server 2008 Update Statistics

    Hi,
    We have SAP running on MS-SQL 2008. Can we use the command 'sp_updatestats' to update stats on all tables in the schema or  is there any option we can schedule a job from DBACOCKPIT?
    Thanks,
    Kris

    Yes, you can use sp_updatestats as described here [MS173804|http://msdn.microsoft.com/en-us/library/ms173804.aspx] with MS SQL Server 2008.
    I do not believe you can create the job from DBACOCKPIT, however.

  • SQL Server Bulk Copy

    The performance optimization guide shows you how to switch between the SQL Server ODBC bulk copy API and SQLBulkOperations API but does not recomend which one works better. Since the default is SQL Server ODBC bulk copy API I assume that is the best option but I wish to test that assumption to see if that is true?
    Edited by: Richard Sherman on Oct 3, 2008 11:53 AM

    Hello,
    we have to use the bulk options with data services and have the same question. Anyone know where a document comparing the two options?
    Thank you very much, Silvia

  • SQL Server runs update on one record, returns -1 records updated to java

    I am trying to troubleshoot an issue in SQL Server. For all the databases in a specific server, the return value for java initiated update statements have completed the update (ie. I can go into SQL Server and verify the values have changed), but returned
    a value of -1 records updated. I am not sure what went wrong to cause this to fail. It works on one server, but not on any databases on the other server and it suddenly changed on Friday, April 10. Here is the results of the java I am running.
    Driver vendor: Microsoft JDBC Driver 4.0 for SQL Server
    DriverVersion: 4.0.4621.201
    dbproduct: Microsoft SQL Server
    JavaPlus Connection Made: no warnings
    Executing :update maxsequence set maxreserved = 401 where sequencename ='SERVERSESSIONSEQ' and maxreserved=400
    Using TYPE_SCROLL_INSENSITIVE
    Execute Returned -- (boolean) --- false
    Execute getUpdateCount -- (num) -1
    Execute took :0(15) secs.
    Update/Deleted :-1 records.
    Fetching/Updating took :0(0) secs.
    I am runnning SQL Server 2012 and Windows 2012R2
    Microsoft SQL Server Management Studio 11.0.2100.60
    Microsoft Analysis Services Client Tools
    11.0.2100.60
    Microsoft Data Access Components (MDAC) 6.3.9600.16384
    Microsoft MSXML 3.0 4.0 6.0 
    Microsoft Internet Explorer 9.11.9600.16518
    Microsoft .NET Framework 4.0.30319.34011
    Operating System 6.3.9600

    Can you clarify why your Java output saying Execute Returned -- (boolean) --- false
    I suspect this update never happened and it is possible to get updated row counts such as by using stored
    procedure and returning @@ROWCOUNT value through return statement to the data set
    Would you like to try this?
    Good Luck! Please Mark This As Answer if it solved your issue. Please Vote This As Helpful if it helps to solve your issue

  • Help: SQL for Bulk update (lead function)

    Hello,
    I am using Oracle11.2. I would like to update the column hist_dttm of tb_hist with the value of column crt_dttm of tb_base in the next row, which is ordered by crt_dttm. here are the details:
    creat table tb_base(tid varchar2(32), crt_dttm timestamp(6));
    creat table tb_hist(tid varchar2(32), crt_dttm timestamp(6), upd_dttm timestamp(6));
    insert into tb_base values ('AAA', to_timestamp('01-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_base values ('AAA', to_timestamp('05-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_base values ('AAA', to_timestamp('16-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_base values ('AAA', to_timestamp('01-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'), null );
    insert into tb_base values ('AAA', to_timestamp('05-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'), null );
    I am using the following SQL to update the upd_dttm column of tb_hist, I expect the upd_dttm will be updated as ''05-12-05 14:00:00.123456' and '16-12-05 14:00:00.123456'. However they remains in NULL. Any suggestion?
    update tb_hist hist
    set (upd_dttm) = (select lead(base.CRT_DTTM over (Partition by base.tid order by base.crt_dttm)
    from tb_base base
    where base.tid = hist.tid
    and base.crt_dttm = hist.crt_dttm)
    ;

    After some modifications in your sample data
    DROP TABLE tb_base;
    DROP TABLE tb_hist;
    create table tb_base(tid varchar2(32), crt_dttm timestamp(6));
    create table tb_hist(tid varchar2(32), crt_dttm timestamp(6), upd_dttm timestamp(6));
    insert into tb_base values ('AAA', to_timestamp('01-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_base values ('AAA', to_timestamp('05-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_base values ('AAA', to_timestamp('16-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff') );
    insert into tb_hist values ('AAA', to_timestamp('01-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'),null  );
    insert into tb_hist values ('AAA', to_timestamp('05-12-05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'),null );The following statement can do the job?
    MERGE INTO tb_hist dst
    USING
      SELECT tid, crt_dttm, LEAD(crt_dttm) OVER(PARTITION BY tid ORDER BY tid, crt_dttm) as d
        FROM tb_base
    ) src
    ON (dst.tid = src.tid AND src.crt_dttm = dst.crt_dttm)
    WHEN MATCHED THEN
      UPDATE SET dst.upd_dttm = src.d;

  • SQL Server 2012 Express bulk Insert flat file 1million rows with "" as delimeter

    Hi,
    I wanted to see if anyone can help me out. I am on SQL server 2012 express. I cannot use OPENROWSET because my system is x64 and my Microsoft office suit is x32 (Microsoft.Jet.OLEDB.4.0).
    So I used Import wizard and is not working either. 
    The only thing that let me import this large file, is:
    CREATE TABLE #LOADLARGEFLATFILE
    Column1
    varchar(100), Column2 varchar(100), Column3 varchar(100),
    Column4 nvarchar(max)
    BULK INSERT
    #LOADLARGEFLATFILE
    FROM 'C:\FolderBigFile\LARGEFLATFILE.txt'
    WITH 
    FIRSTROW = 2,
    FIELDTERMINATOR ='\t',
    ROWTERMINATOR ='\n'
    The problem with CREATE TABLE and BULK INSERT is that my flat file comes with text qualifiers - "". Is there a way to prevent the quotes "" from loading in the bulk insert? Below is the data. 
    Column1
    Column2
    Column3
    Column4
    "Socket Adapter"
    8456AB
    $4.25
    "Item - Square Drive Socket Adapter | For "
    "Butt Splice" 
    9586CB
    $14.51
    "Item - Butt Splice"
    "Bleach"
    6589TE
    $27.30
    "Item - Bleach | Size - 96 oz. | Container Type"
    Ed,
    Edwin Lopera

    Hi lgnusLumen,
    According to your description, you use BULK INSERT to import data from a data file to the SQL table. However, to be usable as a data file for bulk import, a CSV file must comply with the following restrictions:
    1. Data fields never contain the field terminator.
    2. Either none or all of the values in a data field are enclosed in quotation marks ("").
    In your data file, the quotes aren't consistent, if you want to prevent the quotes "" from loading in the bulk insert, I recommend you use SQL Server Import and Export Wizard tools in SQL Server Express version. area, it will allow to strip the
    double quote from columns, you can review the following screenshot.
    In other SQL Server version, we can use SQL Server Integration Services (SSIS) to import data from a flat file (.csv) with removing the double quotes. For more information, you can review the following article.
    http://www.mssqltips.com/sqlservertip/1316/strip-double-quotes-from-an-import-file-in-integration-services-ssis/
    In addition, you can create a function to convert a CSV to a usable format for Bulk Insert. It will replace all field-delimiting commas with a new delimiter. You can then use the new field delimiter instead of a comma. For more information, see:
    http://stackoverflow.com/questions/782353/sql-server-bulk-insert-of-csv-file-with-inconsistent-quotes
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • SQL Server UPDATE much faster than Oracle -- why??

    The following MS-SQL Server (2000) UPDATE takes 10 seconds, while the same Oracle 10.2.0.1 UPDATE takes over 15 minutes. The data is exactly the same (data set of 97,000 rows) and the cpu/disk/memory configs are similar for both databases. The Oracle tables have indexes and statistics gathered. The Oracle Explain Plan shows that indexes are being used for the SELECT table joins, but not for the UPDATE table.
    Any ideas?
    MS-SQL UPDATE:
    update lib_cust_summary
    set rev_2003 =
    SELECT
    sum(ohd.PRICE_EXTENSION)
    FROM
    oehist_summary ohs
    ,customers c
    ,oehist_detail ohd
    ,lib_cust_summary lcs
    WHERE c.cust_nbr     = lcs.cust_nbr
    and c.cust_nbr = ohs.cust_nbr
    and ohs.INVOICE_NBR = ohd.INVOICE_NBR
    and c.cust_nbr = lcs2.cust_nbr
    and ohs.CUST_NBR NOT LIKE 'XFER%'
    and     ohd.prod_grp not in ('AV','FE')
    AND ohs.INVOICE_DATE between {ts '2003-01-01 00:00:00'} and {ts '2003-12-31 00:00:00'}
    group by c.cust_nbr
    from lib_cust_summary lcs2;
    Oracle UPDATE
    update lib_cust_summary lcs /*+ index(lcs lib_cust_summary_pk) */
    set rev_2003 =
    SELECT /*+ index(lcs lib_cust_summary_pk) */
    sum(ohd.PRICE_EXTENSION)
    FROM
    oehist_summary ohs
    ,customers c
    ,oehist_detail ohd
    WHERE c.cust_nbr = lcs.cust_nbr
    and c.cust_nbr = ohs.cust_nbr
    and ohs.INVOICE_NBR = ohd.INVOICE_NBR
    and ohs.CUST_NBR NOT LIKE 'XFER%'
    and     ohd.prod_grp not in ('AV','FE')
    AND ohs.INVOICE_DATE between '01-JAN-2003' and '31-DEC-2003'
    group by c.cust_nbr
    )

    update lib_cust_summary lcs /*+ index(lcs
    s lib_cust_summary_pk) */
    set rev_2003 =Why are you forcing the optimizer to read a full table by using an index?
    SELECT /*+ index(lcs lib_cust_summary_pk) */What happens if you remove this hint also?
    sum(ohd.PRICE_EXTENSION)
    FROM
    oehist_summary ohs
    ,customers c
    ,oehist_detail ohd
    WHERE c.cust_nbr = lcs.cust_nbr
    and c.cust_nbr = ohs.cust_nbr
    and ohs.INVOICE_NBR = ohd.INVOICE_NBR
    and ohs.CUST_NBR NOT LIKE 'XFER%'
    and     ohd.prod_grp not in ('AV','FE')
    AND ohs.INVOICE_DATE between '01-JAN-2003' and
    d '31-DEC-2003'You should not compare dates to strings
    AND ohs.INVOICE_DATE between to_date('01-JAN-2003','DD-MON-YYYY') and
    to_date('31-DEC-2003','DD-MON-YYY')What are the plans now and after the changes?

  • Backup Failed in SQL server 2008

    Backup is failing for only one database on the server.
    Msg 3201, Level 16, State 1, Line 1
    Cannot open backup device 'F:\databasename_backup_2014_07_29.bak'.
     Operating system error 5(failed to retrieve text for this error. Reason: 15105).
    Msg 3013, Level 16, State 1, Line 1
    BACKUP DATABASE is terminating abnormally.
    ** SAME DATABASE BACKUP IS COMPLETED SUCCESSFULLY ON OTHER DRIVE **
    we have tried the below steps but still it is failed.
    Microsoft SQL Server 2008 R2 (SP2) - 10.50.3720.0 (X64)   Apr 27 2012 13:51:37   Copyright (c) Microsoft Corporation  
     Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)  
    1.checked for any spaces is th database name --No space
    2.added service account to administrator .
    3.provided full access to backup folder.
    4.Compatibilty is 80 .
    5.created backup devide to same location and tried still it got failed.
    10 percent processed.
    20 percent processed.
    30 percent processed.
    40 percent processed.
    50 percent processed.
    60 percent processed.
    70 percent processed.
    Msg 3202, Level 16, State 1, Line 1
    Write on "F:\Data\Backup\New_Backup_databasename.bak" failed: 665(failed to retrieve text for this error. Reason: 15105)
    Msg 3013, Level 16, State 1, Line 1
    BACKUP DATABASE is terminating abnormally.
    6.Changed the database ower to service account,NO luck

    Hi,
    How big is database ? Does F drive has enough space on it. Issue does not seems with SQL Server backup it is with F drive or network connecting Server to drives.
    Can you give more information about F drive is it a SAN, Local disk ?
    If SQL server backup would have been issue it would have not processed uptill 70 % ( unles its bug). First error message with OS error 5 means access denied. Ater then you gave necessary rights and now backup issue is not due to SQL Server but while writing
    to F drive some unusual thing is happeing which is causing backup to fail.Can you also involve SAN team as well.
    ** SAME DATABASE BACKUP IS COMPLETED SUCCESSFULLY ON OTHER DRIVE **
    Does this mean backup of same database completes successfully on other drive if so it is a SAN issue or connection issue between SAN and server
    Is SQL server 2008 updated to latest service pack ? Why do you use 80 compatibility mode. Although these questions are not realted to backup
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • SQL Server Service Packs (2008, 2008R2, 2012)

    Hi all,
    it appears that no one took care of installing Service Packs for our SQL Servers from WSUS and now i have to do it. What i have:
    MS SQL Server 2008 R2 Service Pack 1
    MS SQL Server 2008 Service Pack 1,2,3
    MS SQL Server 2012 Service Pack 1,2
    As you could see some of them a really old.
    1. The fact that everything is running so far without any problems and complains bring the question: Do I have to install Service Packs?
    2. Is it ok if I go directly to the latest Service Pack for each Server or i have to go the "entire road" installing one after another.
    3. What is the best way to do the updates: Install all other security and critical updates, restart the server, then install the service pack and restart again the server. 
    Actually my knowledge for SQL Server and Updates for it are not so big that's why i want to apologies for the stupid questions. Thanks in advance

    1. The fact that everything is running so far without any problems and complains bring the question: Do I have to install Service Packs?
    Hi,
    Yes very much recommended if your SQL server 2008 is not at SP/Sp4 it would not come under extended support purview. If you have 2008 r2  not with SP3 again you are out of extended support.  For 2012 as well apply Sp2 .Mainstarem support for 2008/2008
    R2 has already ended
    2. Is it ok if I go directly to the latest Service Pack for each Server or i have to go the "entire road" installing one after another.
    Hi,
    Yes you can directly upgrade to SQL
    Server 2008 SP4 because SP are cumulative and latest SP will include all fixes present in one released before it . As a fact you can always apply latest SP for any SQL server version for fact that it is cumulative. Dont go for SP3 go for SP4 in 2008 and
    SP3 for 2008 r2
    3. What is the best way to do the updates: Install all other security and critical updates, restart the server, then install the service pack and restart again the server.
    Best way can be referred from below docs
    http://msdn.microsoft.com/en-us/library/dd638062%28v=sql.100%29.aspx
    http://social.technet.microsoft.com/wiki/contents/articles/25632.how-to-install-sql-server-2012-sp2-on-standalone-sql-server-instance.aspx
    Just above doc is for 2012 but will hold true for 2008 as well. SP might require restart of Windows machine on which SQL Server resides.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Copy the data from Sql Server to edirectory using java

    Hi ,
    I am new to e directory.I don't know how it works.Can some one assist
    me on this ,I have to extract data from SQL Server and update these
    data in edirectory.This is needs to be done using java.
    If any one can provide me the sample code or please suggest how to
    proceed .
    Thanks in advance
    dukewarm
    dukewarm's Profile: http://forums.novell.com/member.php?userid=53430
    View this thread: http://forums.novell.com/showthread.php?t=373051

    dukewarm;1792481 Wrote:
    > Hi ,
    >
    > I am new to e directory.I don't know how it works.Can some one assist
    > me on this ,I have to extract data from SQL Server and update these
    > data in edirectory.This is needs to be done using java.
    >
    > If any one can provide me the sample code or please suggest how to
    > proceed .
    >
    > Thanks in advance
    Read the values from SQL server and use LDAP to update the data in
    eDirectory.
    Thomas
    thsundel
    thsundel's Profile: http://forums.novell.com/member.php?userid=128
    View this thread: http://forums.novell.com/showthread.php?t=373051

Maybe you are looking for

  • How to change input with insignia

    Can anyone help me with changing the input on my Insignia tv with my Verizon remote? I am using the Phillips remote. Thanks for any help you can offer.

  • Report to find Users that cannot Shop?

    Hi All, Is there a report/program in SRM 5.0 that can tell what users are not configured correctly that will not allow them to shop? Also does the same report run in SRM 4.0? Thanks, Nikhil Edited by: Nikhil Malvankar on Nov 24, 2008 6:49 PM Edited b

  • Changing stage size midway through movie

    Hi I have downloaded a Flash movie from a library which I want to use as part of a larger movie. The downloaded Flash movie is 300 pixels square, while the movie I want to use it in will be 765 x 100 pixels. The downloaded movie has a number of layer

  • HP 1315 all in one

    I am trying to print with my HP 1315 all in one and it tells me the paper tray is empty when it is full of paper. What do I need to do to correct this problem

  • Is OS X Server for me?

    Hello all, I've scanned through the forums trying to find my answer, but I found that each question is unique and so is mine: I want to start hosting webpages, now my ISP gives me static 5 IP's, I can already see that I will need to host more than 10