Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2008, 01:27 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jeff,

How can I get the number of rows failed after call exec(@sql)? I need this number to inform client if any error happen.

 
Old July 17th, 2008, 01:58 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And also, I wish if one row get error,just skip this row,continue insert other rows.
Is this default properties?

Do need to to set value for MAXERRORS for my purpose?

 
Old July 17th, 2008, 02:31 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

You would need to set MaxErrors.

--Jeff Moden
 
Old July 17th, 2008, 02:41 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I have a lots of questions.

When I insert data from temp table to real table, if the row already exists in real table, don't input the row from temp table to real table,

Do the following codes do what I wish?

CREATE TABLE #tempTbl( -- same field and same order as real table
   STR_ID numeric(18, 0) NOT NULL, --Primary key
   COMPID numberic(18,0) NOT NULL, --Primary key
   TITLE VARCHAR(50),
   PFIELD VARCHAR(50),
   PDESC VARCHAR(50)
)

INSERT realTabl (STR_ID, COMPID, TITLE, PFIELD, PDESC)
SELECT * ----1: is it ok here like this
FROM #tempTbl src
WHERE NOT EXISTS (SELECT * '----2: is it ok here like this
FROM realTabl tbl
WHERE tbl.STR_ID = src.STR_ID and tbl.COMPID = src.COMPID)

Thanks!


 
Old July 17th, 2008, 02:46 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Looks like it... I just hate correlated subqueries because they have to do a SELECT for every row that needs to be found... that's as bad as a cursor. That's why I did it like I did in example #3.

--Jeff Moden
 
Old July 17th, 2008, 03:01 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, Jeff, I also don't like above codes I posted above. ok now I understand why you use WHERE p.SomeID IS NULL in your codes, since after left outer join, if the row is not in my real table then p.SomeID IS NULL. so we only insert all the rows with p.SomeID IS NULL to my real table, did my understanding right?

Now I set MAXERRORS=1000 for BULK INSERT.

Jeff,

1: would you please tell me how I can get the number of rows failed?
2: can I modify your codes as the following:

INSERT INTO realTable
        (SomeID,SomeDesc)
 SELECT * ------------------------use * ok or have to list all fields? s.SomeID, s.SomeDesc
   FROM TempTbl s
   LEFT OUTER JOIN realTable p
     ON s.STR_ID = p.STR_ID and
        s.COMP_ID = p.COMP_ID
  WHERE p.STR_ID IS NULL

Thanks for your help and your time!



 
Old July 17th, 2008, 04:49 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Given that the TempTbl was created *from* the realTbl, you should be okay using
    SELECT *
but if you do that then you should *OMIT* the list of fields after the INSERT INTO that you show there. Thus:
    
Code:
INSERT INTO realTable
Code:
    SELECT * 
    FROM TempTbl s ... etc ...
 
Old July 17th, 2008, 05:38 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Old Pedant.

How about get the number of rows failed? I need this number, if any row failed I will tell client to recheck the data.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Write Tab-delimited text file VikramMullick Pro VB.NET 2002/2003 1 May 5th, 2006 11:18 AM
Tab delimited Split ajindal General .NET 1 April 25th, 2006 08:20 AM
Split a long vedio to several parts Andraw Classic ASP Basics 0 May 3rd, 2005 10:58 AM
Frustrations of Split(long) enterbase Access VBA 6 January 27th, 2004 04:19 PM
Upload tab delimited into Access? mariakovacs Classic ASP Databases 0 October 10th, 2003 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.