Advertisement

10.03.2008 at 10:45AM PDT, ID: 23785819
[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

MS SQL cursor problem checking for not null or blank strings

Asked by MiracleByDesign in MS SQL Server, SQL Server 2005

Tags:

Hello Experts,
I would like you to view my code to see if you can determine the error if possible.  I am populating a cursor and I need to check if each variable has data in it.  If it does, I need to update another field with a "T" which is used to protect fields on the front-end of the application.  The problem is all of my flag fields are being updated with a "T" whether there is data or not.  Hopefully this will be quick for someone to catch my error but I need this before Tuesday if possible.

Thanks,
Miracle By DesignStart 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:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
Begin Transaction
	--Declare cursor columns
		--RC_EmployerChanges cursor variables
	Declare @ecTelephoneTWS varchar(14),
			@ecSecTelephoneTWS varchar(14),
			@ecPreparedByPhoneTWS varchar(14),
			@ecEmailTWS varchar(60),
			@ecContactFirstNameTWS varchar(60),
			@ecContactLastNameTWS varchar(60),
			@ecContactTitleTWS varchar(60),
			@ecContactTelephoneTWS varchar(14),
			@ecDiscontinuedDateTWS datetime,
			@ecCeasedWagesDateTWS datetime,
		--RC_EmployerRep cursor variables
			@erContactFirstNameTWS varchar(60),
			@erContactLastNameTWS varchar(60),
			@erContactTitleTWS varchar(60),
			@erContactTelephoneTWS varchar(14),
		--RC_Leasing cursor variables 
			@leContactFirstNameTWS varchar(60),
			@leContactLastNameTWS varchar(60),
			@leContactTitleTWS varchar(60),
			@leContactTelephoneTWS varchar(14),
		--RC_Payroll cursor variables 
			@paContactFirstNameTWS varchar(60),
			@paContactLastNameTWS varchar(60),
			@paContactTitleTWS varchar(60),
			@paContactTelephoneTWS varchar(14),
		--RC_TransferAll cursor variables
			@taContactFirstNameTWS varchar(60),
			@taContactLastNameTWS varchar(60),
			@taContactTitleTWS varchar(60),
			@taContactTelephoneTWS varchar(14),
		--RC_TrasnferPart cursor variables
			@tpContactFirstNameTWS varchar(60),
			@tpContactLastNameTWS varchar(60),
			@tpContactTitleTWS varchar(60),
			@tpContactTelephoneTWS varchar(14),
			@tpRetainedContactFirstNameTWS varchar(60),
			@tpRetainedContactLastNameTWS varchar(60),
			@tpRetainedContactTitleTWS varchar(60),
			@tpRetainedContactTelephoneTWS varchar(14),
			@tpRetainedNumOfEmployeesTWS int
	--cursor for RC_EmployerChanges
	Declare ecTWS_Flags cursor Fast_Forward 
			For select Telephone, SecTelephone, PreparedByPhone, Email, 
			ContactFirstName, ContactLastName, ContactTitle, ContactTelephone, DiscontinuedDate,
			CeasedWagesDate From RC_EmployerChanges
	Open ecTWS_Flags 
	Fetch Next From ecTWS_Flags Into @ecTelephoneTWS, @ecSecTelephoneTWS, @ecPreparedByPhoneTWS, 
		  @ecEmailTWS, @ecContactFirstNameTWS, @ecContactLastNameTWS, @ecContactTitleTWS, 
		  @ecContactTelephoneTWS, @ecDiscontinuedDateTWS, @ecCeasedWagesDateTWS
	While @@Fetch_Status = 0
			Begin
				If @ecTelephoneTWS is not null Or @ecTelephoneTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set TelephoneTWS = 'T'
					End
				If @ecSecTelephoneTWS is not null Or @ecSecTelephoneTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set SecTelephoneTWS = 'T'
					End
				If @ecPreparedByPhoneTWS is not null Or @ecPreparedByPhoneTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set PreparedByPhoneTWS = 'T'
					End
				If @ecEmailTWS is not null Or @ecEmailTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set EmailTWS = 'T'
					End
			
				If @ecContactFirstNameTWS is not null Or @ecContactFirstNameTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set ContactFirstNameTWS = 'T'
					End
				If @ecContactLastNameTWS is not null Or @ecContactLastNameTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set ContactLastNameTWS = 'T'
					End
				If @ecContactTitleTWS is not null Or @ecContactTitleTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set ContactTitleTWS = 'T'
					End
				If @ecContactTelephoneTWS is not null Or @ecContactTelephoneTWS <> ' '
					Begin	
						Update RC_EmployerChanges
						Set ContactTelephoneTWS = 'T'
					End
				If @ecDiscontinuedDateTWS is not null Or @ecDiscontinuedDateTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set DiscontinuedDateTWS = 'T'
					End
				If @ecCeasedWagesDateTWS is not null Or @ecCeasedWagesDateTWS <> ' '
					Begin
						Update RC_EmployerChanges
						Set CeasedWagesDateTWS = 'T'
					End
				Fetch Next From ecTWS_Flags Into @ecTelephoneTWS, @ecSecTelephoneTWS, @ecPreparedByPhoneTWS,
				      @ecEmailTWS, @ecContactFirstNameTWS, @ecContactLastNameTWS, @ecContactTitleTWS, 
					  @ecContactTelephoneTWS, @ecDiscontinuedDateTWS, @ecCeasedWagesDateTWS
			End
	Close ecTWS_Flags
	Deallocate ecTWS_Flags
	--cursor for RC_EmployerRep
	Declare erTWS_Flags cursor Fast_Forward 
			For select ContactFirstName, ContactLastName, ContactTitle, ContactTelephone
			From RC_EmployerRep
	Open erTWS_Flags 
	Fetch Next From erTWS_Flags Into @erContactFirstNameTWS, @erContactLastNameTWS, @erContactTitleTWS, @erContactTelephoneTWS
	While @@Fetch_Status = 0
		Begin
				If @erContactFirstNameTWS is not null Or @erContactFirstNameTWS <> ' '
					Begin
						Update RC_EmployerRep
						Set ContactFirstNameTWS = 'T'
					End
				If @erContactLastNameTWS is not null Or @erContactLastNameTWS <> ' '
					Begin
						Update RC_EmployerRep
						Set ContactLastNameTWS = 'T'
					End
				If @erContactTitleTWS is not null Or @erContactTitleTWS <> ' '
					Begin
						Update RC_EmployerRep
						Set ContactTitleTWS = 'T'
					End
				If @erContactTelephoneTWS is not null Or @erContactTelephoneTWS <> ' '
					Begin
						Update RC_EmployerRep
						Set ContactTelephoneTWS = 'T'
					End
		  Fetch Next From erTWS_Flags Into @erContactFirstNameTWS, @erContactLastNameTWS, @erContactTitleTWS, @erContactTelephoneTWS
		End	
	Close erTWS_Flags
	Deallocate erTWS_Flags
	--cursor for RC_Leasing
	Declare leTWS_Flags cursor Fast_Forward 
			For select ContactFirstName, ContactLastName, ContactTitle, ContactTelephone
			From RC_Leasing
	Open leTWS_Flags 
	Fetch Next From leTWS_Flags Into @leContactFirstNameTWS, @leContactLastNameTWS, @leContactTitleTWS, @leContactTelephoneTWS
	While @@Fetch_Status = 0
		Begin
		
			If @leContactFirstNameTWS is not null Or @leContactFirstNameTWS <> ' '
				Begin
					Update RC_Leasing
					Set ContactFirstNameTWS = 'T'
				End
			If @leContactLastNameTWS is not null Or @leContactLastNameTWS <> ' '
				Begin
					Update RC_Leasing
					Set ContactLastNameTWS = 'T'
				End 
			If @leContactTitleTWS is not null Or @leContactTitleTWS <> ' '
				Begin
					Update RC_Leasing
					Set ContactTitleTWS = 'T'
				End
			If @leContactTelephoneTWS is not null Or @leContactTelephoneTWS <> ' '
				Begin
					Update RC_Leasing
					Set ContactTelephoneTWS = 'T'
				End
 
		Fetch Next From leTWS_Flags Into @leContactFirstNameTWS, @leContactLastNameTWS, @leContactTitleTWS, @leContactTelephoneTWS
		End
	Close leTWS_Flags
	Deallocate leTWS_Flags
	--cursor for RC_Payroll
	Declare paTWS_Flags cursor Fast_Forward 
			For select ContactFirstName, ContactLastName, ContactTitle, ContactTelephone
			From RC_Payroll
	Open paTWS_Flags 
	Fetch Next From paTWS_Flags Into @paContactFirstNameTWS, @paContactLastNameTWS, @paContactTitleTWS, @paContactTelephoneTWS
	While @@Fetch_Status = 0
		Begin
		
			If @paContactFirstNameTWS is not null Or @paContactFirstNameTWS <> ' '
				Begin
					Update RC_Payroll
					Set ContactFirstNameTWS = 'T'
				End
			If @paContactLastNameTWS is not null Or @paContactLastNameTWS <> ' '
				Begin
					Update RC_Payroll
					Set ContactLastNameTWS = 'T'
				End
			If @paContactTitleTWS is not null Or @paContactTitleTWS <> ' '
				Begin
					Update RC_Payroll
					Set ContactTitleTWS = 'T'
				End
			If @paContactTelephoneTWS is not null Or @paContactTelephoneTWS <> ' '
				Begin
					Update RC_Payroll
					Set ContactTelephoneTWS = 'T'
				End
			Fetch Next From paTWS_Flags Into @paContactFirstNameTWS, @paContactLastNameTWS, @paContactTitleTWS, @paContactTelephoneTWS
		End
	Close paTWS_Flags
	Deallocate paTWS_Flags
	--cursor for RC_TransferAll
	Declare taTWS_Flags cursor Fast_Forward 
			For select ContactFirstName, ContactLastName, ContactTitle, ContactTelephone
			From RC_TransferAll
	Open taTWS_Flags 
	Fetch Next From taTWS_Flags Into @taContactFirstNameTWS, @taContactLastNameTWS, @taContactTitleTWS, @taContactTelephoneTWS
	While @@Fetch_Status = 0
		Begin
			If @taContactFirstNameTWS is not null Or @taContactFirstNameTWS <> ' '
				Begin
					Update RC_TransferAll
					Set ContactFirstNameTWS = 'T'
				End
			If @taContactLastNameTWS is not null Or @taContactLastNameTWS <> ' '
				Begin
					Update RC_TransferAll
					Set ContactLastNameTWS = 'T'
				End
			If @taContactTitleTWS is not null Or @taContactTitleTWS <> ' '
				Begin
					Update RC_TransferAll
					Set ContactTitleTWS = 'T'
				End
			If @taContactTelephoneTWS is not null Or @taContactTelephoneTWS <> ' '
				Begin
					Update RC_TransferAll
					Set ContactTelephoneTWS = 'T'
				End
 
			Fetch Next From taTWS_Flags Into @taContactFirstNameTWS, @taContactLastNameTWS, @taContactTitleTWS, @taContactTelephoneTWS
 
		End
	Close taTWS_Flags
	Deallocate taTWS_Flags
	--cursor for RC_TransferPart
	Declare tpTWS_Flags cursor Fast_Forward 
			For select ContactFirstName, ContactLastName, ContactTitle, ContactTelephone, 
					   RetainedContactFirstName, RetainedContactLastName, RetainedContactTitle,
					   RetainedContactTelephone, RetainedNumOfEmployees
			From RC_TransferPart
	Open tpTWS_Flags 
	Fetch Next From tpTWS_Flags Into @tpContactFirstNameTWS, @tpContactLastNameTWS, @tpContactTitleTWS, @tpContactTelephoneTWS,
		  @tpRetainedContactFirstNameTWS, @tpRetainedContactLastNameTWS, @tpRetainedContactTitleTWS, @tpRetainedContactTelephoneTWS,
		  @tpRetainedNumOfEmployeesTWS
		
	While @@Fetch_Status = 0
		Begin
			If @tpContactFirstNameTWS is not null Or @tpContactFirstNameTWS <> ' '
				Begin
					Update RC_TransferPart
					Set ContactFirstNameTWS = 'T'
				End
			If @tpContactLastNameTWS is not null Or @tpContactLastNameTWS <> ' '
				Begin
					Update RC_TransferPart			
					Set ContactLastNameTWS = 'T'
				End
			If @tpContactTitleTWS is not null Or @tpContactTitleTWS <> ' '
				Begin
					Update RC_TransferPart
					Set ContactTitleTWS = 'T'
				End
			If @tpContactTelephoneTWS is not null Or @tpContactTelephoneTWS <> ' '
				Begin
					Update RC_TransferPart
					Set ContactTelephoneTWS = 'T'
				End
			If @tpRetainedContactFirstNameTWS is not null Or @tpRetainedContactFirstNameTWS <> ' '
				Begin
					Update RC_TransferPart
					Set RetainedContactFirstNameTWS = 'T'
				End
			If @tpRetainedContactLastNameTWS is not null Or @tpRetainedContactLastNameTWS <> ' '
				Begin
					Update RC_TransferPart
					Set RetainedContactLastNameTWS = 'T'
				End
			If @tpRetainedContactTitleTWS is not null Or @tpRetainedContactTitleTWS <> ' '
				Begin
					Update RC_TransferPart
					Set RetainedContactTitleTWS = 'T'
				End
			If @tpRetainedContactTelephoneTWS is not null Or @tpRetainedContactTelephoneTWS <> '' 
				Begin
					Update RC_TransferPart
					Set RetainedContactTelephoneTWS = 'T'
				End
			If @tpRetainedNumOfEmployeesTWS is not null Or @tpRetainedNumOfEmployeesTWS <> ' '
				Begin
					Update RC_TransferPart
					Set RetainedNumOfEmployeesTWS = 'T'
				End
			
 
		Fetch Next From tpTWS_Flags Into @tpContactFirstNameTWS, @tpContactLastNameTWS, @tpContactTitleTWS, @tpContactTelephoneTWS,
		  @tpRetainedContactFirstNameTWS, @tpRetainedContactLastNameTWS, @tpRetainedContactTitleTWS, @tpRetainedContactTelephoneTWS,
		  @tpRetainedNumOfEmployeesTWS
		End
	Close tpTWS_Flags
	Deallocate tpTWS_Flags
Commit Transaction
[+][-]10.03.2008 at 10:48AM PDT, ID: 22636235

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

 
[+][-]10.03.2008 at 10:51AM PDT, ID: 22636268

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

 
[+][-]10.03.2008 at 10:53AM PDT, ID: 22636286

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

 
[+][-]10.03.2008 at 01:38PM PDT, ID: 22637824

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

 
[+][-]10.03.2008 at 01:51PM PDT, ID: 22637925

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

 
[+][-]10.03.2008 at 01:57PM PDT, ID: 22637986

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

 
[+][-]10.03.2008 at 02:11PM PDT, ID: 22638117

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

 
[+][-]10.03.2008 at 02:14PM PDT, ID: 22638143

View this solution now by starting your 14-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: MS SQL 2005
Sign Up Now!
Solution Provided By: BrandonGalderisi
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.03.2008 at 02:52PM PDT, ID: 22638398

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

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628