Solved

Shopping Cart Unique OrderNumber?

Posted on 2006-07-12
1
426 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now