Solved

Shopping Cart Unique OrderNumber?

Posted on 2006-07-12
1
429 Views
Last Modified: 2013-11-29
Here's a good Shopping Cart question to bennifit many who are stuck using random OrderNumbers.

I need to select the largest OrderNumber from one table, increment 1, then insert the new larger number into a second table

Q. How can I combine the two seperate SQLs below into one classy and usefull SQL?


SELECT 1+ MAX(col_OrderNumber) FROM FirstTable

INSERT INTO SecondTable (col_OrderNumber, col_FirstName, col_LastName)
                           VALUES ( '" OrderNumber,'" + FirstName.ToString() + "', '" + LastName.ToString() + "')
0
Comment
Question by:kvnsdr
1 Comment
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 250 total points
ID: 17096619
either use an identity column on table 2
or continue as you are ....

you normally will need to use the order number many times so have to "capture" it once via a select anyway...





alternative is
SELECT 1+ MAX(col_OrderNumber) FROM FirstTable

INSERT INTO SecondTable (col_OrderNumber, col_FirstName, col_LastName)
SELECT 1+ MAX(col_OrderNumber),'firstnamevalue','lastnamevalue'  FROM FirstTable
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CDC and AOG on MS SQL 2012 13 25
SQL Server 2008 R2, need a pivot/cross tab query... 4 30
Parse this column 6 27
too many installs coming along with SQL 2016? 1 18
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question