473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

INSERT INTO - Data is not inserted - Using #temp table to populate actual table

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',03004,'A000-AA00',2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ;'HARLEY.I',03004,'A000-AA00',2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ;

3.Problem - gets to line

BEGIN TRAN <---------- skips
rest
INSERT INTO timesheet.dbo.table1

4.Checked permissions for table + sproc - ok

What am I doing wrong ?

Any comments most helpful......
CREATE PROCEDURE [dbo].[procTimesheetInsert_Testing](
@TimesheetDetails 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, @TimesheetCount1 int
DECLARE @TS_LastEdit smalldatetime
DECLARE @Last_Editby smalldatetime
DECLARE @User_Confirm bit
DECLARE @User_Confirm_Date smalldatetime
DECLARE @DetailCount int
DECLARE @Error int
/* Validate input parameters. Assume success. */

SELECT @RetCode = 1, @RetMsg = ''

IF @TimesheetDetails 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 #tmpTimesheetDetails
(
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
#tmpTimesheetDetails(RE_Code,PR_Code,AC_Code,WE_Da te,SAT,SUN,MON,TUE,WED,THU,FRI,Notes,General,PO_Nu mber,WWL_Number,CN_Number)
VALUES ( '
SELECT @TimesheetCount=0
WHILE LEN( @TimesheetDetails) > 1
BEGIN
SELECT @SQLComplete = @SQLBase + LEFT( @TimesheetDetails,
Charindex(';', @TimesheetDetails) -1) + ')'
EXEC(@SQLComplete)
SELECT @TimesheetCount = @TimesheetCount + 1
SELECT @TimesheetDetails = RIGHT( @TimesheetDetails, Len(
@TimesheetDetails)-Charindex(';', @TimesheetDetails))
END

IF (SELECT Count(*) FROM #tmpTimesheetDetails) <> @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.table1
select RE_Code,PR_Code,AC_Code,WE_Date,SAT,SUN,MON,TUE,WE D,THU,FRI,Notes,General,PO_Number,WWL_Number,CN_Nu mber
FROM #tmpTimesheetDetails

-- 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
Jul 20 '05 #1
2 16043
ImraneA (i.*****@weir.co.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.table1
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 #tmpTimesheetDetails

-- 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
Jul 20 '05 #2
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!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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
3
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...
9
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,...
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...
16
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...
4
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...
5
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...
2
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...
6
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,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.