473,473 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

mssql syntax error in stored proc

2 New Member
i have a stored procedure like below
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE display_Products
  2. @CategoryID int
  3.  AS
  4. BEGIN
  5.      DECLARE @authors_cursor CURSOR
  6.     SET @authors_cursor =CURSOR FAST_FORWARD
  7.     FOR SELECT TOP 10 COUNT(iProductFK) AS s ,iProductFK 
  8.     FROM tblOrderDetail  WHERE iProductFK IN(SELECT iProductFK FROM tblCategoryProduct WHERE iCategoryFK = @CategoryID)
  9.     GROUP BY iProductFK
  10.     ORDER BY s desc
  11.     DECLARE @a int
  12.      DECLARE @b int
  13.     declare @c varchar(200)
  14.     OPEN @authors_cursor
  15.     FETCH NEXT FROM @authors_cursor  INTO @a, @b
  16.     WHILE @@FETCH_STATUS = 0
  17.     BEGIN
  18.         set @c=@c+convert(varchar,@b)+'*'
  19.         FETCH NEXT FROM @authors_cursor INTO @a, @b
  20.     END
  21. CLOSE @authors_cursor
  22. DEALLOCATE @authors_cursor
  23. return @c
  24. END
  25. GO
  26.  
when i try to execute this procedure from a php page
this was the code i put[php]
mssql_bind($sq_top,"@CategoryID",$LintCatID,SQLINT 4);
mssql_bind($sq_top,"RETVAL",stripslashes($pID),SQL VARCHAR,false, false, 200);
$res_top=mssql_execute($sq_top);[/php]
This was the error message i got

Warning: mssql_execute() [function.mssql-execute]: message: Syntax error converting the varchar value '71643*71318*20114*258681*20097*232296*42432*71501 *71410*233548*' to a column of data type int. (severity 16) in C:\wamp\www\lion\subcat.php on line 45

Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in C:\wamp\www\lion\subcat.php on line 45

if anybody know how to solve this please help me
Mar 19 '08 #1
4 3295
ronverdonk
4,258 Recognized Expert Specialist
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 19 '08 #2
ronverdonk
4,258 Recognized Expert Specialist
Problem is in your stored procedure, not in PHP.

I will move this thread to the appropriate forum.

moderator
Mar 19 '08 #3
deepuv04
227 Recognized Expert New Member
i have a stored procedure like below
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE display_Products
  2. @CategoryID int
  3.  AS
  4. BEGIN
  5.      DECLARE @authors_cursor CURSOR
  6.     SET @authors_cursor =CURSOR FAST_FORWARD
  7.     FOR SELECT TOP 10 COUNT(iProductFK) AS s ,iProductFK 
  8.     FROM tblOrderDetail  WHERE iProductFK IN(SELECT iProductFK FROM tblCategoryProduct WHERE iCategoryFK = @CategoryID)
  9.     GROUP BY iProductFK
  10.     ORDER BY s desc
  11.     DECLARE @a int
  12.      DECLARE @b int
  13.     declare @c varchar(200)
  14.     OPEN @authors_cursor
  15.     FETCH NEXT FROM @authors_cursor  INTO @a, @b
  16.     WHILE @@FETCH_STATUS = 0
  17.     BEGIN
  18.         set @c=@c+convert(varchar,@b)+'*'
  19.         FETCH NEXT FROM @authors_cursor INTO @a, @b
  20.     END
  21. CLOSE @authors_cursor
  22. DEALLOCATE @authors_cursor
  23. return @c
  24. END
  25. GO
  26.  
when i try to execute this procedure from a php page
this was the code i put[php]
mssql_bind($sq_top,"@CategoryID",$LintCatID,SQLINT 4);
mssql_bind($sq_top,"RETVAL",stripslashes($pID),SQL VARCHAR,false, false, 200);
$res_top=mssql_execute($sq_top);[/php]
This was the error message i got

Warning: mssql_execute() [function.mssql-execute]: message: Syntax error converting the varchar value '71643*71318*20114*258681*20097*232296*42432*71501 *71410*233548*' to a column of data type int. (severity 16) in C:\wamp\www\lion\subcat.php on line 45

Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in C:\wamp\www\lion\subcat.php on line 45

if anybody know how to solve this please help me

Hi,

First initialize @c to empty string after your declaration.
and in the while loop change the statement
set @c=@c+convert(varchar,@b)+'*' to
set @c=@c+convert(varchar(10),@b)+'*'

can you tell me what is the data type of column iProductFK

thanks
Mar 19 '08 #4
sujiforsql
2 New Member
Hi,

First initialize @c to empty string after your declaration.
and in the while loop change the statement
set @c=@c+convert(varchar,@b)+'*' to
set @c=@c+convert(varchar(10),@b)+'*'

can you tell me what is the data type of column iProductFK

thanks
iProductFK is of type int with size 4
Mar 24 '08 #5

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

Similar topics

1
by: Philip Mette | last post by:
I am in a crunch and need to covert this Oracle statement to MSSQL. Is there any Oracle/MSSQL experts out there that can help me? I do not understand the syntax enough to modify this. Thanks so...
4
by: Don | last post by:
I have MSSQL2k SP3a on WIN2k SP4. moved a Date/log files to this server about a week ago from a SQL7 server and attached it to this new Sql2k server. everything works fine for about 24hrs and...
1
by: dmalhotr2001 | last post by:
Hi, I have an issue with my query. 1. I have 1 stored proc which have execution calls to multiple stored procs within it. 2. I want to wrap that main stored proc in the transaction and...
1
by: Jen S | last post by:
I feel like I'm missing something obvious here, but I'm stumped... I have a stored procedure with code that looks like: INSERT INTO MyTableA ( ...fields... ) VALUES (...values...) IF...
0
by: Mike Thomas | last post by:
This one must be very simple. I am trying to run an SQL Serv 7.0 stored proc from a VBA module in an Access 2000 app. This stored proc runs fine when I remove the parameters from the stored proc...
14
by: aaron kempf | last post by:
I find that ADP does not support any Stored Procedures that use the 'CREATE PROC spHAPPY' syntax. CREATE PROC syntax is listed in books online. This syntax should be supported Here is a...
3
by: Michael | last post by:
Hi Everyone, I'm having a slight problem, I hope I didn't overlook something. I'm getting the following error when I try to execute the function below: Incorrect syntax near 'intake_GetListSet'."...
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'." ...
2
by: Penstar | last post by:
I have a basic Stored proc and keep getting a Syntax error. The SQL works fine, but not in the stored proc. CREATE DEFINER=`time`@`%` PROCEDURE `spAppendTimesheet`(); BEGIN UPDATE tempam1t SET...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.