Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need a sql query in SQL Server

Status
Not open for further replies.

PeriyurParthi

IS-IT--Management
Jul 18, 2001
258
IN
thanks for your immdeiate response, i think you have not understood my problem. let me explain in detail.

i have 3 master tables called m1,m2,m3 and i have a trasaction table called t1. iam inserting datas THRU VB useing insert query.

INSERT INTO T1 VALUES("CODE", "NAME",PRODUCT CODE FROM M1 WHERE PRODUCTNAME="TEST", CATEGORY CODE FROM M2 WHERE CATEGORYNAME="TEST1" )

FOR THE ABOVE PROBLEM I NEED SQL QUERY
HOPE U HAVE GOT
THANKS
PARTHI
 
I think what you need is something like this...

INSERT INTO T1 VALUES(CODE, NAME,PRODUCT CODE, CATEGORY CODE)
SELECT CODE,
NAME,
[PRODUCT CODE],
(SELECT [CATEGORY CODE] FROM M2 WHERE
CATERGORYNAME='TEST1')
FROM M1,
WHERE PRODUCTNAME='TEST'
 
INSERT INTO T1
(fieldCode,fieldName,
fieldProductCode, fieldCategoryCode)
VALUES
(
"CODE",
"NAME",
(select [PRODUCT CODE] FROM M1 WHERE PRODUCTNAME="TEST"),
(select [CATEGORY CODE] FROM M2 WHERE CATEGORYNAME="TEST1")
)

Does this work for you?
 
thanks for all your replies, i think u havent understood my proble, let me explain once again
i have 1 transaction table and 2 or 3 master tables, i need insert code in trasaction table from master table, hope u have understood,
thanks
parthi
 
Maybe you didn't make your problem clear enough....which of these are you are asking for?

1.
You have a table T1 with the columns CODE, NAME, PRODUCT CODE, CATEGORY CODE
You want to put the product code from table M1 into the T1.PRODUCT CODE and the category code from table M2 into T1.CATEGORY CODE

or

2.
You have a table T1 with the columns CODE, NAME)
You want to put the product code from table M1 into the T1.CODE column and the category code from table M2 into the T1.NAME column

#1 is what everyone is giving you the solution to.

SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top