Hi there
Application : Access v2K/SQL 2K
Jest : Using sproc to append records into SQL table
Jest sproc :
1.Can have more than 1 record - so using ';' to separate each line
from each other.
2.Example of data
'HARLEY.I',0300 4,'A000-AA00',2003-08-29,0,0,7.5,7.5, 7.5,7.5,7.0,'No tes','General', 1,2,3;'HARLEY.I ',03004,'A000-AA00',2003-08-29,0,0,7.5,7.5, 7.5,7.5,7.0,'No tes','General', 1,2,3;
3.Problem - gets to line
BEGIN TRAN <---------- skips
rest
INSERT INTO timesheet.dbo.t able1
4.Checked permissions for table + sproc - ok
What am I doing wrong ?
Any comments most helpful......
CREATE PROCEDURE [dbo].[procTimesheetIn sert_Testing](
@TimesheetDetai ls varchar(5000) = NULL,
@RetCode int = NULL OUTPUT,
@RetMsg varchar(100) = NULL OUTPUT,
@TimesheetID int = NULL OUTPUT)
WITH RECOMPILE
AS
SET NOCOUNT ON
DECLARE @SQLBase varchar(8000), @SQLBase1 varchar(8000)
DECLARE @SQLComplete varchar(8000) ,@SQLComplete1 varchar(8000)
DECLARE @TimesheetCount int, @TimesheetCount 1 int
DECLARE @TS_LastEdit smalldatetime
DECLARE @Last_Editby smalldatetime
DECLARE @User_Confirm bit
DECLARE @User_Confirm_D ate smalldatetime
DECLARE @DetailCount int
DECLARE @Error int
/* Validate input parameters. Assume success. */
SELECT @RetCode = 1, @RetMsg = ''
IF @TimesheetDetai ls IS NULL
SELECT @RetCode = 0,
@RetMsg = @RetMsg +
'Timesheet line item(s) required.' + CHAR(13) + CHAR(10)
/* Create a temp table parse out each Timesheet detail from input
parameter string,
count number of detail records and create SQL statement to
insert detail records into the temp table. */
CREATE TABLE #tmpTimesheetDe tails
(
RE_Code varchar(50),
PR_Code varchar(50),
AC_Code varchar(50),
WE_Date smalldatetime,
SAT REAL DEFAULT 0,
SUN REAL DEFAULT 0,
MON REAL DEFAULT 0,
TUE REAL DEFAULT 0,
WED REAL DEFAULT 0,
THU REAL DEFAULT 0,
FRI REAL DEFAULT 0,
Notes varchar(255),
General varchar(50),
PO_Number REAL,
WWL_Number REAL,
CN_Number REAL)
SELECT @SQLBase ='INSERT INTO
#tmpTimesheetDe tails(RE_Code,P R_Code,AC_Code, WE_Date,SAT,SUN ,MON,TUE,WED,TH U,FRI,Notes,Gen eral,PO_Number, WWL_Number,CN_N umber)
VALUES ( '
SELECT @TimesheetCount =0
WHILE LEN( @TimesheetDetai ls) > 1
BEGIN
SELECT @SQLComplete = @SQLBase + LEFT( @TimesheetDetai ls,
Charindex(';', @TimesheetDetai ls) -1) + ')'
EXEC(@SQLComple te)
SELECT @TimesheetCount = @TimesheetCount + 1
SELECT @TimesheetDetai ls = RIGHT( @TimesheetDetai ls, Len(
@TimesheetDetai ls)-Charindex(';', @TimesheetDetai ls))
END
IF (SELECT Count(*) FROM #tmpTimesheetDe tails) <> @TimesheetCount
SELECT @RetCode = 0, @RetMsg = @RetMsg + 'Timesheet Details
couldn''t be saved.' + CHAR(13) + CHAR(10)
-- If validation failed, exit proc
IF @RetCode = 0
RETURN
-- If validation ok, continue
SELECT @RetMsg = @RetMsg + 'Timesheet Details ok.' + CHAR(13) +
CHAR(10)
/* RETURN*/
-- Start transaction by inserting into Timesheet table
BEGIN TRAN
INSERT INTO timesheet.dbo.t able1
select RE_Code,PR_Code ,AC_Code,WE_Dat e,SAT,SUN,MON,T UE,WED,THU,FRI, Notes,General,P O_Number,WWL_Nu mber,CN_Number
FROM #tmpTimesheetDe tails
-- Check if insert succeeded. If so, get ID.
IF @@ROWCOUNT = 1
SELECT @TimesheetID = @@IDENTITY
ELSE
SELECT @TimesheetID = 0,
@RetCode = 0,
@RetMsg = 'Insertion of new Timesheet failed.'
-- If order is not inserted, rollback and exit
IF @RetCode = 0
BEGIN
ROLLBACK TRAN
-- RETURN
END
--RETURN
SELECT @Error =@@error
print ''
print "The value of @error is " + convert (varchar, @error)
return
GO 2 16069
ImraneA (i.*****@weir.c o.uk) writes: 1.Can have more than 1 record - so using ';' to separate each line from each other.
But yet in the procedure you have:
INSERT INTO timesheet.dbo.t able1 select E_Code, PR_Code, C_Code, WE_Date, SAT,SUN, MON, TUE, WED, THU, FRI, Notes, General, PO_Number, WWL_Number, CN_Number FROM #tmpTimesheetDe tails
-- Check if insert succeeded. If so, get ID. IF @@ROWCOUNT = 1 SELECT @TimesheetID = @@IDENTITY
The test data you supplied produced two rows, so you wind up in
ELSE SELECT @TimesheetID = 0, @RetCode = 0, @RetMsg = 'Insertion of new Timesheet failed.'
And rollback the whole affair.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Hi there
After looking at your comments - you were correct. Been working on main
body of sproc very intensively, got to end logic went abit astray.
Fixed that - ok.
Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jason |
last post by:
The best way to explain this is by example.
I have a source table with many columns.
Source
SYMBOL
EXCHANGE_NAME
CUSIP
TYPE
ISSUE_NAME
|
by: xMANIGHTx |
last post by:
I'm new to DTS. I read some docs before adventuring into this matter.
I still haven't found in all the docs I read if there is some "built-in" DTS
task or function or wathever, to do a mixed "insert/update" import from a
source, giving a unique field as primary key.
I'll try to be more specific. The problem I would like to solve is this:
I have a source file (csv) but it could be any source. I must check this
file for all the records and...
|
by: Martin |
last post by:
Hello,
I'm new with triggers and I can not find any good example on how to
do the following:
I have two tables WO and PM with the following fields:
WO.WONUM, VARCHAR(10)
WO.PMNUM, VARCHAR(10)
WO.PROBLEMCODE, VARCHAR(8)
|
by: Carl |
last post by:
Hi,
I hope someone can share some of their professional advice and help me out
with my embarissing problem concerning an Access INSERT query. I have never
attempted to create a table with one-to-one relationship but on this
occasion
I must keep username/password details within a seperate table.
Here's the basic specs and database schema:
-------------------------------------------
|
by: LP |
last post by:
Hi,
Every morning a .NET application downloads a file with cumulative data which
needs to be appended to SQL Server table. This program needs to identify
records that have not been previously inserted (there's a unique identifier
field) and only insert those. Also I must reuse our class that does updates,
it basically can update any table by using SqlDataAdapter .update method. So
I have to rule out bulk inserts, DTS, etc...
I think I...
| |
by: Chris Kratz |
last post by:
Hello all,
We have run into what appears to be a problem with rules and subselects in
postgres 7.4.1. We have boiled it down to the following test case. If
anyone has any thoughts as to why this would be happening, we would
appreciate feedback.
We have tested on 7.3.4, 7.3.6 and 7.4.1 and all exhibit the same behavior.
Test case one tries to populate table2 from table1 with records that are not
in table2 already. Table2 gets...
|
by: das |
last post by:
hello all,
this might be simple:
I populate a temp table based on a condition from another table:
select @condition = condition from table1 where id=1
in my stored procedure I want to do this:
if @condition = 0
|
by: mike |
last post by:
I'm looking for an efficient way to populate derived columns when I
insert data into a table in SQL Server. In Informix and PostgreSQL
this is easily done using the "for each row..." syntax, but all I've
been able to come up with for SQL Server is the following:
create table testtrigger(id integer unique, b integer, c integer)
go
create trigger testtrigger_ins on testtrigger
for insert as
|
by: lenygold via DBMonster.com |
last post by:
Hi everybody:
What is the best way to
I have 10 tables with similar INSERT requiremnts.
INSERT INTO ACSB.VAATAFAE
WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS
( SELECT AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP
FROM VAATAFAA
WHERE AB_TP_ACNT_STAT_CD <0),
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |