473,406 Members | 2,369 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,406 software developers and data experts.

Inserting concatenated data with while construct

7
I am trying to insert records from one table to another using the WHILE construct, I have managed to move all of the data with the exception of one concatenated field. I can't figure out how to concatenate 'GSA' and the @N into GSAOrderNo column in the TempWebOrders table. The @N is incrementing. If anyone can help, please assist. See code below:

-TIA

-Gabe

Use SMS
Declare @N as nvarchar(10)


SELECT @N = MAX (RIGHT(Order_no, 4))
FROM [Order]

USE SC
--Columns that will be used to loop through
--the rows of this table
DECLARE @NumberRecords int, @RowCount int
DECLARE @Order_No int, @System varchar(3), @clerk varchar(3), @custname nvarchar (152), @camp nvarchar(50), @bldg_no nvarchar(50), @phone_no nvarchar(50), @Online_Order_No float, @Webstatus varchar(4), @Orderway varchar(6), @Order_Date datetime, @Order_time datetime, @organization nvarchar(50), @apoc nvarchar(137), @custacct_no nvarchar(75), @card_exp_date nvarchar(50), @GSAOrderNo nvarchar(50)

--Insert the resultset we wan to loop through
--into the TempWebOrders table
INSERT INTO TempWebOrders (Order_No, [System], clerk, custname, camp, bldg_no, phone_no, Online_Order_No, Webstatus, Orderway, Order_Date, Order_time, organization, apoc, custacct_no, card_exp_date, GSAOrderNo)
SELECT Order_No, [System], clerk, custname, camp, bldg_no, phone_no, Online_Order_No, Webstatus, Orderway, Order_Date, Order_time, organization, apoc, custacct_no, card_exp_date, GSAOrderNo = @N
FROM WebOrders


--Get the number of records in the TempWebOrders table
SET @NumberRecords = @@ROWCOUNT
SET @RowCount = 1

--loop through all records in the TempWebOrders table
--using the WHILE loop construct
WHILE @RowCount <= @NumberRecords

BEGIN

SET @N = @N + 1
SELECT @Order_No = Order_No, @System = [System], @clerk = clerk, @custname = custname, @camp = camp, @bldg_no = bldg_no, @phone_no = phone_no, @Online_Order_No = Online_Order_No, @Webstatus = Webstatus, @Orderway = Orderway, @Order_Date = Order_Date, @Order_time = Order_time, @organization = organization, @apoc = apoc, @custacct_no = custacct_no, @card_exp_date = card_exp_date
FROM TempWebOrders
WHERE RowID = @RowCount
SET @RowCount = @RowCount + 1
END
May 14 '09 #1
4 2191
ck9663
2,878 Expert 2GB
Try using IDENTITY instead.

--- CK
May 15 '09 #2
GabeM
7
I don't understand by what you mean by Identity. What does the Identity have to do with the concatenated string?
May 16 '09 #3
ck9663
2,878 Expert 2GB
What will happen if this stored proc ran simultaneously? You can not always be sure with your @n + 1 value.

To address your concatenation, can't you convert the numeric to string and concatenate the two strings?

--- CK
May 16 '09 #4
GabeM
7
I will try to convert it, but I don't think it will work. Thanks for replying.

-Gabe
May 17 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: B Love | last post by:
Hello Group, I have 2 text fields that I would like to concatenate for use in a table. One field is an ordinary text box. The other is a simple combo box which I use to select one of about ten...
4
by: Kurt | last post by:
I'm using the fConcatChild function posted at http://www.mvps.org/access/modules/mdl0004.htm to return a field from the Many table of a 1:M relationship into a concatenated string. The function...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
10
by: Szabolcs Horvát | last post by:
Consider the attached example program: an object of type 'A' is inserted into a 'map<int, Am;'. Why does 'm;' call the copy constructor of 'A' twice in addition to a constructor call? The...
9
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
1
by: win | last post by:
I am trying to insert some data using FormView which works fine but I do not know how to include hiddenfield and bind them in the construct so I can insert information like modify date, etc.. ...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: cluce | last post by:
I am trying to read a csv file with user info (username, password, email, address, city, zip, state, etc.) I am inserting the username, password, email into the aspnet_memberhsip table using the...
5
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.