Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shopping Cart Unique OrderNumber?

Posted on 2006-07-12
1
Medium Priority
?
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

636 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