Advertisement

10.15.2008 at 08:48PM PDT, ID: 23819168
[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!

7.8

Stor_Proc works when called from query analyzer but doesn't work when called from other Stor_Proc

Asked by gastip in MS SQL Server, SQL Server 2005

Tags: ,

Hello Guys/Gals,
I'm trying to modify a shopping cart that I've purchased to insert data from one table into another table using a stor_proc.

It works when I call it from the query window like so: EXEC trumpet_webdev.WorldShip_i 133

When I call it from inside a different stor_proc using this code:             
                                           Declare @LastOrderID int
            Select @LastOrderID = SCOPE_IDENTITY()
            EXEC [xxxxx].[WorldShip_i] @LastOrderID

It will only insert the @lastOrderID. The dynamic sql has been eating me alive, which is partially explains why this is such a hack. I've been trying anything I can think of to work around the problem.

Thank you in advance for any help!!!
Start Free Trial
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:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
ALTER PROCEDURE [xxxxx].[WorldShip_i]
 
@LastOrderID int
 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
 
	
	BEGIN
		Declare @ShippingSelected nvarchar(50)
		Declare @InvoiceNumber nvarchar(50)
		Declare @CompanyName nvarchar(50)
		Declare @Attention nvarchar(50)
		Declare @Address1 nvarchar(50)
		Declare @Address2 nvarchar(50)
		Declare @City nvarchar(50)
		Declare @State nvarchar(50)
		Declare @Zip nvarchar(50)
		Declare @Country nvarchar(50)
		Declare @Phone nvarchar(50)
		Declare @Email nvarchar(50)
		
		DECLARE @SQLString NVARCHAR(500)
		DECLARE @ParmDefinition NVARCHAR(500)
		DECLARE @ShippingMethodOut NVARCHAR(500)
		DECLARE @OrderNumberOut NVARCHAR(500)
		Declare @CompanyOut nvarchar(50)
		Declare @Address1Out nvarchar(50)
		Declare @Address2Out nvarchar(50)
		Declare @CityOut nvarchar(50)
		Declare @StateOut nvarchar(50)
		Declare @ZipOut nvarchar(50)
		Declare @CountryOut nvarchar(50)
		Declare @PhoneOut nvarchar(50)
		Declare @LastOrderIDParam int
		
		Set @SQLString = N'Select 
			@EmailOut = UserEmail, 
			@ShippingMethodOut = ShippingMethodDisplayName, 
			@OrderNumberOut = OrderNumber,
			@CompanyOut = substring(ShippingAddress, CHARINDEX(''<Company>'', ShippingAddress), CHARINDEX(''</Company>'', ShippingAddress) - CHARINDEX(''<Company>'', ShippingAddress))
			FROM dbo.bvc_order where id = @LastOrderIDParam'
 
		SET @ParmDefinition = N'@LastOrderIDParam int, 
			@EmailOut varchar(50) output, 
			@ShippingMethodOut varchar(50) output, 
			@OrderNumberOut varchar(50) output,
			@CompanyOut varchar(50) output'
		Execute sp_executesql
		@SQLString,
		@ParmDefinition,
		@LastOrderIDParam = @LastOrderId, 
		@EmailOut = @Email OUTPUT,
		@ShippingMethodOut = @ShippingSelected OUTPUT,
		@OrderNumberOut = @InvoiceNumber OUTPUT,
		@CompanyOut = @CompanyName OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress1 nvarchar(500)
		DECLARE @ParmDefinitionAddress1 NVARCHAR(500)
		Set @SQLStringAddress1 = N'select 
				@Address1Out = substring(ShippingAddress, CHARINDEX(''<Line1>'', ShippingAddress), CHARINDEX(''</Line1>'', ShippingAddress) - CHARINDEX(''<Line1>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress1 = N'@LastOrderIDParam int, 
				@Address1Out varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress1,
			@ParmDefinitionAddress1,
			@LastOrderIDParam = @LastOrderId, 
			@Address1Out = @Address1 OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress2 nvarchar(500)
		DECLARE @ParmDefinitionAddress2 NVARCHAR(500)
		Set @SQLStringAddress2 = N'select 
				@Address2Out = substring(ShippingAddress, CHARINDEX(''<Line2>'', ShippingAddress), CHARINDEX(''</Line2>'', ShippingAddress) - CHARINDEX(''<Line2>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress2 = N'@LastOrderIDParam int, 
				@Address2Out varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress2,
			@ParmDefinitionAddress2,
			@LastOrderIDParam = @LastOrderId, 
			@Address2Out = @Address2 OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress3 nvarchar(500)
		DECLARE @ParmDefinitionAddress3 NVARCHAR(500)
		Set @SQLStringAddress3 = N'select 
				@CityOut = substring(ShippingAddress, CHARINDEX(''<City>'', ShippingAddress), CHARINDEX(''</City>'', ShippingAddress) - CHARINDEX(''<City>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress3 = N'@LastOrderIDParam int, 
				@CityOut varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress3,
			@ParmDefinitionAddress3,
			@LastOrderIDParam = @LastOrderId, 
			@CityOut = @City OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress4 nvarchar(500)
		DECLARE @ParmDefinitionAddress4 NVARCHAR(500)
		Set @SQLStringAddress4 = N'select 
				@StateOut = substring(ShippingAddress, CHARINDEX(''<RegionName>'', ShippingAddress), CHARINDEX(''</RegionName>'', ShippingAddress) - CHARINDEX(''<RegionName>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress4 = N'@LastOrderIDParam int, 
				@StateOut varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress4,
			@ParmDefinitionAddress4,
			@LastOrderIDParam = @LastOrderId, 
			@StateOut = @State OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress5 nvarchar(500)
		DECLARE @ParmDefinitionAddress5 NVARCHAR(500)
		Set @SQLStringAddress5 = N'select 
				@ZipOut = substring(ShippingAddress, CHARINDEX(''<PostalCode>'', ShippingAddress), CHARINDEX(''</PostalCode>'', ShippingAddress) - CHARINDEX(''<PostalCode>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress5 = N'@LastOrderIDParam int, 
				@ZipOut varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress5,
			@ParmDefinitionAddress5,
			@LastOrderIDParam = @LastOrderId, 
			@ZipOut = @Zip OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress6 nvarchar(500)
		DECLARE @ParmDefinitionAddress6 NVARCHAR(500)
		Set @SQLStringAddress6 = N'select 
				@CountryOut = substring(ShippingAddress, CHARINDEX(''<CountryName>'', ShippingAddress), CHARINDEX(''</CountryName>'', ShippingAddress) - CHARINDEX(''<CountryName>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress6 = N'@LastOrderIDParam int, 
				@CountryOut varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress6,
			@ParmDefinitionAddress6,
			@LastOrderIDParam = @LastOrderId, 
			@CountryOut = @Country OUTPUT
	END
 
	BEGIN
		Declare @SQLStringAddress7 nvarchar(500)
		DECLARE @ParmDefinitionAddress7 NVARCHAR(500)
		Set @SQLStringAddress7 = N'select 
				@PhoneOut = substring(ShippingAddress, CHARINDEX(''<Phone>'', ShippingAddress), CHARINDEX(''</Phone>'', ShippingAddress) - CHARINDEX(''<Phone>'', ShippingAddress))
				FROM dbo.bvc_order where id = @LastOrderIDParam'
		Set @ParmDefinitionAddress7 = N'@LastOrderIDParam int, 
				@PhoneOut varchar(50) output'
		Execute sp_executesql
			@SQLStringAddress7,
			@ParmDefinitionAddress7,
			@LastOrderIDParam = @LastOrderId, 
			@PhoneOut = @Phone OUTPUT
	END
 
	BEGIN
 
/*
		SET @CompanyName = REPLACE(@CompanyName,'<Company>','')
		SET @Address1 = REPLACE(@Address1,'<Line1>','')
		SET @Address2 = REPLACE(@Address2,'<Line2>','')
		SET @City = REPLACE(@City,'<City>','')
		SET @State = REPLACE(@State,'<RegionName>','')
		SET @Zip = REPLACE(@Zip,'<PostalCode>','')
		SET @Country = REPLACE(@Country,'<CountryName>','')
		SET @Phone = REPLACE(@Phone,'<Phone>','')
 
 
		SET @CompanyName = REPLACE(REPLACE(@CompanyName,'<Company>',''), char(39), char(39) + char(39)) 
		SET @Address1 = REPLACE(REPLACE(@Address1,'<Line1>',''), char(39), char(39) + char(39))
		SET @Address2 = REPLACE(REPLACE(@Address2,'<Line2>',''), char(39), char(39) + char(39))
		SET @City = REPLACE(REPLACE(@City,'<City>',''), char(39), char(39) + char(39))
		SET @State = REPLACE(REPLACE(@State,'<RegionName>',''), char(39), char(39) + char(39))
		SET @Zip = REPLACE(REPLACE(@Zip,'<PostalCode>',''), char(39), char(39) + char(39))
		SET @Country = REPLACE(REPLACE(@Country,'<CountryName>',''), char(39), char(39) + char(39))
		SET @Phone = REPLACE(REPLACE(@Phone,'<Phone>',''), char(39), char(39) + char(39))
	
*/
 
 
		Insert into WorldShip
		(
			OrderTableID,
			InvoiceNumber,
			CompanyName,
			Address1,
			Address2,
			City,
			State,
			Zip,
			Country,
			Phone,
			Email,
			ShippingSelected
		)
		values
		(
			@LastOrderID,
			@InvoiceNumber,
			@CompanyName,
			@Address1,
			@Address2,
			@City,
			@State,
			@Zip,
			@Country,
			@Phone,
			@Email,
			@ShippingSelected
		)
 
	END
END
GO
 
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
[+][-]10.15.2008 at 09:04PM PDT, ID: 22728007

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 09:58PM PDT, ID: 22728196

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2008 at 12:38PM PDT, ID: 22744460

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2008 at 12:14PM PDT, ID: 22749377

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.27.2008 at 01:10PM PDT, ID: 22816266

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2008 at 08:58PM PDT, ID: 22837930

View this solution now by starting your 7-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: MS SQL Server, SQL Server 2005
Tags: t-sql, Sql 2005, n/a
Sign Up Now!
Solution Provided By: gastip
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628