Question : Procedure not run correctly when parameter include non en character (SQL2005)

I use the procedure as attached. And run it as below.

EXECUTE UpdateSample @SampleName = 'YOR', @OperStatus = 'Before'

It is used to check the parameter condition and make some update.

But if the 2nd parameter change to non english character as below, it cannot run correctly. The column itself is set to non en. It is ok for common SQL.

EXECUTE UpdateSample @SampleName = 'YOR', @OperStatus = N'xxx'

Any suggestion, thanks.
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:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[UpdateSample] 
	@SampleName varchar(200) = NULL, 
	@OperStatus varchar(200) = NULL
AS
BEGIN
	SET NOCOUNT ON;
	if (@OperStatus = 'Before' or @OperStatus = N'¿¿¿')
		Begin
		UPDATE AveBefore 
		set t1Close = (select avg(trend.t1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus 
					   and spot.model = @SampleName),   
			t2Close = (select avg(trend.t2Close)
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Close = (select avg(trend.I1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I2Close = (select avg(trend.I2Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I1Motor = (select avg(trend.I1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Motor = (select avg(trend.I2Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t1Motor = (select avg(trend.t1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			t1Trip = (select avg(trend.t1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t2Trip = (select avg(trend.t2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Trip = (select avg(trend.I1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Trip = (select avg(trend.I2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName)
		WHERE Model=@SampleName;
		UPDATE StdDevBefore 
		set t1Close = (select STDEV(trend.t1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),   
			t2Close = (select STDEV(trend.t2Close)
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Close = (select STDEV(trend.I1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I2Close = (select STDEV(trend.I2Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I1Motor = (select STDEV(trend.I1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Motor = (select STDEV(trend.I2Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t1Motor = (select STDEV(trend.t1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			t1Trip = (select STDEV(trend.t1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t2Trip = (select STDEV(trend.t2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Trip = (select STDEV(trend.I1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Trip = (select STDEV(trend.I2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName)
		WHERE Model=@SampleName;
	END

	else if (@OperStatus = 'After' or @OperStatus = N'¿¿¿')
	Begin
		UPDATE AveAfter 
		set t1Close = (select avg(trend.t1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),   
			t2Close = (select avg(trend.t2Close)
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Close = (select avg(trend.I1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I2Close = (select avg(trend.I2Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I1Motor = (select avg(trend.I1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Motor = (select avg(trend.I2Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t1Motor = (select avg(trend.t1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			t1Trip = (select avg(trend.t1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t2Trip = (select avg(trend.t2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Trip = (select avg(trend.I1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Trip = (select avg(trend.I2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName)
		WHERE Model=@SampleName;
		UPDATE StdDevAfter  
		set t1Close = (select avg(trend.t1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),   
			t2Close = (select avg(trend.t2Close)
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Close = (select avg(trend.I1Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I2Close = (select avg(trend.I2Close) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I1Motor = (select avg(trend.I1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Motor = (select avg(trend.I2Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t1Motor = (select avg(trend.t1Motor) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			t1Trip = (select avg(trend.t1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			t2Trip = (select avg(trend.t2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName),
			I1Trip = (select avg(trend.I1Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName), 
			I2Trip = (select avg(trend.I2Trip) 
					   from trend inner join spot on trend.spotkey = spot.spotid
					   where trend.Status = @OperStatus
					   and spot.model = @SampleName)
		WHERE Model=@SampleName;
	END
END

Answer : Procedure not run correctly when parameter include non en character (SQL2005)

i agree, try this way

 

ALTER PROCEDURE [dbo].[UpdateSample]
@SampleName varchar(200) = NULL,
@OperStatus nvarchar(200) = NULL

Random Solutions  
 
programming4us programming4us