[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

TSQL Insert Update

Asked by aneilg in SQL Query Syntax, SQL Server 2005

I have the following sp.
What I want to achieve is get my stored to update the newly created table with the results from my select query.

I have sort of built my select query up, but I am not sure how to go about inserting the information into the newly created table.

The first bit I need to do get TblSiteDetails.SitePostcode AS SitePostcode
Then insert the results into [03_PCode]

Then split the first two characters of the post code and enter the results into       
[01_PCode3] and [02_PCode2]

Eg
[03_PCode] bb1 5hh
[02_PCode] bb
[01_PCode] bb
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
USE [Reports]
GO
/****** Object:  StoredProcedure SET ANSI_NULLS ON
 
GO
SET QUOTED_IDENTIFIER ON
GO
 
--Unit Type fields added to both parts of the Union query
 
ALTER PROCEDURE [dbo].[sp_rptSalesSchedule]
	
	@FromDate DATETIME,
	@ToDate DATETIME
 
AS
 
BEGIN
 
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[rptSalesSchedule]') 
		AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [rptSalesSchedule]
 
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[rptSalesSchedule]') 
		AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
CREATE TABLE [rptSalesSchedule] (
	[01_PCode3] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[02_PCode2] [varchar] (50),
	[03_PCode] [varchar] (50),
	[04_Engineers] [varchar] (50),
	[05_Appt Date] [varchar] (50),
	[06_Appt Time] [varchar] (50),
	[07_SSPX] [varchar] (50),
	[08_GCN] [varchar] (50),
	[09_WT] [varchar] (50),
	[10_Report Cat] [varchar] (50),
	[11_Unit Type] [varchar] (50),
	[12_Supplier] [varchar] (50),
	[12_Month] [varchar] (50),
	[12_Report] [varchar] (50)
) ON [PRIMARY]
 
 
--INSERT INTO [rptSalesSchedule] GCN SELECT GroupCustName AS GCN FROM rptSalesSchedule
 
---- [01_PCode3]
--UPDATE tblSalesSchedule
--SET [01_PCode3]=
 
 
---- [02_PCode2]
--UPDATE tblSalesSchedule
--SET [02_PCode2]=
 
 
---- [03_PCode]
--UPDATE tblSalesSchedule
--SET [03_PCode]=
 
 
SELECT DISTINCT
	TblApptDetails.ApptDetailsID,
	TblJobDetails.Jobcode,
	Null AS [Commscode],
	TblSSPX.SSPX AS SSPX, 
	TblGroupCustNameLog.GroupCustName AS GCN,
	TblSiteDetails.SitePostcode AS SitePostcode,
	TblJobType.JobType AS JobType,
	TblResource.Fullname AS [Sales Name],
 
 		dbo.FormatDateTime(TblApptDetails.ApptConfirmedDate, 'DD/MM/YYYY') 
			AS [Confirmed Date], 
 
		CASE 
				WHEN dbo.FormatDateTime(TblApptDetails.ApptConfirmedTime,'hh:mm 24') <> '00:00' 
				THEN dbo.FormatDateTime(TblApptDetails.ApptConfirmedTime,'hh:mm 24')
			ELSE  dbo.FormatDateTime(TblApptDetails.TimeSlotFrom,'hh:mm 24') + ' - ' 
							+ dbo.FormatDateTime(TblApptDetails.TimeSlotTo,'hh:mm 24')
		END AS 'Latest Confirmed Time'
 
FROM TblProgressStatus
		INNER JOIN
			TblJobStatusLog ON TblProgressStatus.ProgressStatusID = TblJobStatusLog.ProgressStatusFK 
		INNER JOIN
			TblResourcesRequired 
		INNER JOIN
			TblSSPX 
		INNER JOIN
			TblGroupCustNameLog ON TblSSPX.SSPXID = TblGroupCustNameLog.SSPXFK 
		INNER JOIN
			TblCustomerLog ON TblSSPX.SSPXID = TblCustomerLog.SSPXFK 
		INNER JOIN
			TblCustomer ON TblCustomerLog.CustomerFK = TblCustomer.CustomerID 
		INNER JOIN
			TblJobDetails ON TblSSPX.SSPXID = TblJobDetails.SSPXFK 
		INNER JOIN
			TblApptDetails ON TblJobDetails.JobDetailsID = TblApptDetails.JobDetailsFK 
						   ON TblResourcesRequired.APPTDetailsFK = TblApptDetails.ApptDetailsID 
		INNER JOIN
			TblResource ON TblResourcesRequired.ResourcesFK = TblResource.ResourceID 
		INNER JOIN
			TblSiteDetails ON TblSSPX.SSPXID = TblSiteDetails.SSPXFK 
 
		LEFT JOIN TblSSPXTariff ON TblSSPX.SSPXID = TblSSPXTariff.SSPXFK 
 
		INNER JOIN
			TblSupplierLog ON TblSSPX.SSPXID = TblSupplierLog.SSPXFK 
		INNER JOIN
			TblSupplier ON TblSupplierLog.SupplierFK = TblSupplier.SupplierID 
						ON TblJobStatusLog.JobDetailsFK = TblJobDetails.JobDetailsID
 
		LEFT JOIN TblUnitDetails 
						ON TblJobDetails.JobDetailsID = TblUnitDetails.JobDetailsFK 
		LEFT JOIN TblUnit 
						ON TblUnitDetails.UnitFK = TblUnit.UnitID 
		LEFT JOIN TblDropDownMaster ON TblUnit.ConnectionMethod = TblDropDownMaster.DropDownMasterID 
		LEFT OUTER JOIN TblJobType  ON TblJobDetails.JobTypeFK = TblJobType.JobTypeID
 
WHERE     
		(TblApptDetails.ApptConfirmedDate 
			BETWEEN @FromDate 
			AND @ToDate) 
			AND (TblCustomerLog.CurrentCustomer = 1) 
			AND (TblSupplierLog.CurrentSupplier = 1) 
			AND (TblApptDetails.CurrentAPPT = 1)
			AND ((TblSSPXTariff.currentTariff IS NULL 
				OR TblSSPXTariff.currentTariff = 1) 
				OR TblJobDetails.MTDsReq = 0)
			AND (TblProgressStatus.ProgressStatusType = 'Appt Confirmed') 
			AND  (TblJobStatusLog.CurrentStatus = 1) 
				--AND ((TblResource.Fullname LIKE '%' + @Engineers +'%') OR (@Engineers Is Null))
				--AND ((TblJobType.JobType LIKE '%' + @JobType +'%') OR (@JobType Is Null))
				--AND ((TblResource.EmployedBy LIKE '%'  + @EmployedBy + '%') OR (@EmployedBy Is Null))
			AND TblGroupCustNameLog.CurrentGroupCustName = 1
 
 
 
 
END
[+][-]11/03/09 06:48 AM, ID: 25729426Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: SQL Query Syntax, SQL Server 2005
Sign Up Now!
Solution Provided By: gohord
Participating Experts: 2
Solution Grade: A
 
[+][-]11/03/09 06:41 AM, ID: 25729353Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 06:46 AM, ID: 25729407Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 06:47 AM, ID: 25729417Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 06:53 AM, ID: 25729477Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 06:54 AM, ID: 25729488Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 07:03 AM, ID: 25729580Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 12:30 AM, ID: 25737382Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 12:37 AM, ID: 25737412Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 04:49 AM, ID: 25738738Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625