knowledge-database (beta)

Current group: dbase.sql

SQL Syntax

SQL Syntax  
Denise
From:Denise
Subject:SQL Syntax
Date:29 Nov 2004 04:07:17 -0800
I am trying to insert rows from a table source in a stored procedure.
I have an order by clause on the select statement which worls
correctly when i run the select statement on its own. However when i
combine the statements the results are not inserted into table in
correct order!!! Can anyone tell me why?? Here is the combined
statement: -

INSERT INTO tblTest2
(id, companyId, accNo, add1, add2, add3,
postCode, county, country, website, dateAdded, isCustomer, statusId,
Comments, productId, typeId, priorityId,
source, rating, jobTitle, phone1, phone2,
mobile, fax, firstname, surname, divisionId, title, receiveMail,
email, areaId, closeDate, primCategory, isCash,
companyName, busId, division, status)
SELECT a.id, a.companyId, a.accNo, a.add1, a.add2, a.add3,
a.postCode, a.county, a.country, a.website, a.dateAdded, a.isCustomer,
a.statusId, a.Comments,
a.productId, a.typeId, a.priorityId, a.source,
a.rating, a.jobTitle, a.phone1, a.phone2, a.mobile, a.fax,
a.firstname, a.surname, a.divisionId, a.title,
a.receiveMail, a.email, a.areaId, a.closeDate,
a.primaryCat, a.isCash, b.name AS companyName, c.id AS busid, d.name
AS Expr1,
e.status AS Expr2
FROM tblLeads a INNER JOIN
tblCustomerCompany b ON a.companyId = b.id INNER
JOIN
tblCustomerToBusiness c ON a.id = c.leadId LEFT
OUTER JOIN
tblCustomerCompanyDivisions d ON a.divisionId =
d.id INNER JOIN
tblLeadStatus e ON a.statusId = e.id
WHERE (a.isCustomer = 1) AND (a.statusId = 1)
ORDER BY b.name
   

Copyright © 2006 knowledge-database   -   All rights reserved