Click here to Skip to main content
15,884,018 members

Comments by PhilLenoir (Top 183 by date)

PhilLenoir 30-Jan-15 12:46pm View    
Using count with a field name excludes records where that field is null. this is great if it's the behaviour you want. Using COUNT(*) returns a count including records with null values, but it is slow on large data sets. IMO the best practice for count is COUNT(1).
PhilLenoir 20-Nov-14 15:37pm View    
If your DBMS/connection capability doesn't allow you to set a time-out but you are working in a multi-thread tool you could fire the query on a thread and kill the thread if it does not return in time.

You don't say what your DBMS is or what your programming toolset is.
PhilLenoir 6-Nov-14 14:58pm View    
Gert, BCP can't see "inserted". BCP establishes a new connection to SQL and the context of the trigger or anything it calls is not available to BCP and BCP cannot be transactional with the trigger.

If you were to insert into another table or have a field "logged" in the table concerned you could then either use BCP to log the contents of that other table (possibly cleaning it up as you go) or have BCP call a stored procedure that selects the data to be logged and cleans up within a transaction.
PhilLenoir 6-Nov-14 14:48pm View    
That's what I was getting at with the log table. Bulk copy will only see anything that's got a global context. You can pass dynamic SQL but not dynamic data. If Gert uses a global construct he needs to make sure that he doesn't have a concurrency issue. The call to xp_cmdshell is synchronous, but the write/reads to a global structure would not be. He could generate a key and pass that to BCP using a dynamic query to remove any possibility of collisions ... or use CLR (possibly the most straightforward solution).. There's not enough detail in the question to post a definitive solution (yet), although these comments might give him all the push he needs.
PhilLenoir 6-Nov-14 14:35pm View    
No problem. If you are still stuck, see if you can make out the sense of the "selector key" questions I posed and feel free to ask for more help.