Solved

Shopping Cart Unique OrderNumber?

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert in derived column 7 30
SQL Replication question 9 43
Sql Server group by 10 27
SQL Server Connection String through a VPN 8 25
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

777 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