Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2007, 07:49 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default INSERT Query

Hi,

I have several fields from Table1 which are populating fields in Table2. In fields 2 & 3 in Table2, I need to populate one or the other dependant on the value of the 1st character in Field4 in Table1.

i.e.
Table1 Field4 = '3xxxx'
then enter value in Table2 Field2
If NOT beginning with '3'
then enter value in Table2 Field3

Code:
INSERT INTO dbo.MER_Sales
(
dbo.MER_Sales.ORDER_ID,
dbo.MER_Sales.MERCHANT,
dbo.MER_Sales.PAYER,
)
SELECT dbo.Progress_salord.[Order Number],
SubString(dbo.progress_cust.[Customer Reference],1,1) = '3', 
SubString(dbo.progress_cust.[Customer Reference],1,1) <> '3'
FROM dbo.Progress_salord INNER JOIN dbo.progress_alloc ON
dbo.Progress_salord.[Sale Or Purchase] = dbo.progress_alloc.[Destination Type]
How do I achieve this?

Thanks in advance,


Neal

A Northern Soul
__________________
Neal

A Northern Soul
 
Old May 2nd, 2007, 08:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think this would do...
Code:
INSERT INTO dbo.MER_Sales
(
dbo.MER_Sales.ORDER_ID,
--dbo.MER_Sales.MERCHANT,
--dbo.MER_Sales.PAYER,
)
SELECT dbo.Progress_salord.[Order Number],
CASE WHEN SubString(dbo.progress_cust.[Customer Reference],1,1) = '3' 
    THEN <Your_Value> ELSE NULL END,
CASE WHEN SubString(dbo.progress_cust.[Customer Reference],1,1) <> '3' 
    THEN <Your_Value> ELSE NULL END
FROM dbo.Progress_salord INNER JOIN dbo.progress_alloc ON
dbo.Progress_salord.[Sale Or Purchase] = dbo.progress_alloc.[Destination Type]
Cheers.

_________________________
- Vijay G
Strive for Perfection
 
Old May 3rd, 2007, 05:18 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Cheers.

Thanks very much.

Neal

A Northern Soul





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Into Query. rupen Access VBA 5 July 30th, 2007 09:58 AM
Where does insert query go? bph Access VBA 5 June 12th, 2007 12:26 PM
New Insert Query Neal SQL Server 2000 3 May 8th, 2007 01:22 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
INSERT INTO QUERY sanjna000 Excel VBA 5 November 26th, 2004 12:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.