473,412 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Why is there an incorrect syntax near the equal sign?

103 100+
I can not figure out why I am getting an error. Can someone help? Here is my code with the line with issue highlighted.
Expand|Select|Wrap|Line Numbers
  1. SET @var1 = ''
  2. SET @var2 = ''
  3. SET @var3 = ''
  4. SET @var4 = ''
  5.  
  6. SELECT @Counter = MIN(ID) FROM #TEMP WHERE ID>0
  7.  
  8. WHILE @Counter > 0
  9. BEGIN
  10. SELECT @key = Phase FROM #TEMP WHERE ID = @Counter
  11. SELECT (CASE WHEN @Key = 1 THEN
  12.          @Var1 = (SELECT Agency FROM #TEMP WHERE ID = @Counter)
This is my whole query for the part I need help with.
Expand|Select|Wrap|Line Numbers
  1. DECLARE @Counter AS INT
  2. DECLARE @key AS INT
  3. DECLARE @var1 AS INT
  4. DECLARE @var2 AS INT
  5. DECLARE @var3 AS INT
  6. DECLARE @var4 AS INT
  7.  
  8. SET @var1 = ''
  9. SET @var2 = ''
  10. SET @var3 = ''
  11. SET @var4 = ''
  12.  
  13. SELECT @Counter = MIN(ID) FROM #TEMP WHERE ID>0
  14.  
  15. WHILE @Counter > 0
  16. BEGIN
  17. SELECT @key = Phase FROM #TEMP WHERE ID = @Counter
  18. SELECT (CASE WHEN @Key = 1 THEN
  19.          @Var1 = (SELECT Agency FROM #TEMP WHERE ID = @Counter)
  20.          @var2 = SELECT Request FROM #TEMP WHERE ID = @Counter
  21.          @var3 = SELECT SourceofFunds FROM #TEMP WHERE ID = @Counter
  22.  
  23.         UPDATE #TEMP
  24.         SET Agency = @Var1
  25.         WHERE Request = @var2 AND SourceofFunds = @var3 AND ID <> @Counter END)
  26.  
  27. END 
  28. SELECT @Counter = MIN(ID) FROM #TEMP WHERE ID>@Counter
  29. END
Feb 8 '13 #1
3 5922
NeoPa
32,556 Expert Mod 16PB
You seem to be treating your variables as both Integer (INT) and string. An INT variable cannot sensibly hold an empty string ('') value.
Feb 9 '13 #2
Rabbit
12,516 Expert Mod 8TB
Get rid of the SELECT on line 18. You may also need a begin and end to surround your then clause in your case statement.

Usually, when you only have one condition, I just use the IF instead of CASE.
Feb 9 '13 #3
deepuv04
227 Expert 100+
change your loop as
Expand|Select|Wrap|Line Numbers
  1. WHILE @Counter > 0
  2. BEGIN
  3.  
  4.     SELECT @key = Phase FROM #TEMP WHERE ID = @Counter
  5.  
  6.     IF @Key = 1
  7.     BEGIN 
  8.         SELECT 
  9.              @Var1 =  Agency ,
  10.              @var2 =  Request,
  11.              @var3 =  SourceofFunds FROM #TEMP WHERE ID = @Counter
  12.  
  13.         UPDATE    #TEMP
  14.         SET        Agency = @Var1
  15.         WHERE    Request = @var2 AND SourceofFunds = @var3 AND ID <> @Counter 
  16.     END
  17.  
  18.     SELECT @Counter = MIN(ID) FROM #TEMP WHERE ID>@Counter
  19. END
  20.  
Feb 11 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Zoury | last post by:
Hi there! :O) I trying to use a COM DLL (made in VB 6.0) from C#... and it hasn't been working well for me this far.. :O/ I did a sample in VB 6.0 that used the DLL and it works great.. so now...
1
by: bdastani | last post by:
I am trying to initialize a dataReader in C#, but I keep on gettin an exception error stating the following: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior,...
1
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
1
by: iporter | last post by:
In the following code, the two Response.Write statements output exactly the same - I can copy and paste both into Query Analyzer, and run them fine. However, if I comment out line 3, the...
5
by: Mario Krsnic | last post by:
Hallo zusammen, I have an app. with SQL-Server. The same page worked fine with Access-DB. Now I have a problem with this command: Dim strSQL As String Dim myConnection As New...
3
by: wallic | last post by:
Hello, This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). ...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
1
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
1
by: Omendra | last post by:
Hi, I am using SQL Server 2005 and i am using Stored Procedure something like :- I am getting error:- Msg 170, Level 15, State 1, Line 18: Incorrect syntax near 'MAX'. DECLARE @jid AS...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.