Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 my first sp is not working because of parameters

Author  Topic 

alejo46
Posting Yak Master

157 Posts

Posted - 2012-01-24 : 14:57:24
Good morning

Please, I need your help, im a newbie in sqlserver, i coded my first sp but its not workig with the input parametres,

ths sp without pameters run OK but what i intended to do is to provide to the sp 2 input parameters: startdate and end date. i.e

exec pr_inci 20120103 20120104

the above sp yields me an error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '2012010

the code is this:
*
Name: pr_inci
Description: count per day the numbere of incidents in table ACA_INCIDENCIA
Author: Alejandro Vargas
Modification Log: Change

Description Date Changed By
Created procedure 2011/01/24 Alejandro Vargas
*/

CREATE PROCEDURE pr_inci

@START_DATE VARCHAR(8)
@END_DATE VARCHAR(8)

AS
SET NOCOUNT ON
SET @START_DATE = '20120103'
SET @END_DATE = '20120104'
SELECT CONVERT(VARCHAR(8),FEC_CREACION,112),COUNT(1) CANTIDAD
from ACA_INCIDENCIA
WHERE ((FEC_CREACION >= @START_DATE AND FEC_CREACION < @END_DATE)
OR (FEC_REAL >= @START_DATE AND FEC_REAL < @END_DATE)
--

1. how to get around this?
2. if i've got to modify thr code to the sp, how can i modify it ?

id appreciate your help

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-24 : 15:08:09
exec pr_inci '20120103', '20120104'

Why are you using varchar for dates though!?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

alejo46
Posting Yak Master

157 Posts

Posted - 2012-01-25 : 10:32:41
I executed and yields me an error:
exec pr_inci '20120103','20120104'

Server: Msg 8146, Level 16, State 2, Procedure pr_inci, Line 0
Procedure pr_inci has no parameters and arguments were supplied.

i already commented the lines that calls the VARS

--SET @START_DATE = '20120103'
--SET @END_DATE = '20120104'

id appreciate your help
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-25 : 10:38:50
quote:
Originally posted by alejo46

Good morning

Please, I need your help, im a newbie in sqlserver, i coded my first sp but its not workig with the input parametres,

ths sp without pameters run OK but what i intended to do is to provide to the sp 2 input parameters: startdate and end date. i.e

exec pr_inci 20120103 20120104

the above sp yields me an error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '2012010

the code is this:
*
Name: pr_inci
Description: count per day the numbere of incidents in table ACA_INCIDENCIA
Author: Alejandro Vargas
Modification Log: Change

Description Date Changed By
Created procedure 2011/01/24 Alejandro Vargas
*/

CREATE PROCEDURE pr_inci
(
@START_DATE VARCHAR(8)
@END_DATE VARCHAR(8)
)
AS
SET NOCOUNT ON
SET @START_DATE = '20120103'
SET @END_DATE = '20120104'
SELECT CONVERT(VARCHAR(8),FEC_CREACION,112),COUNT(1) CANTIDAD
from ACA_INCIDENCIA
WHERE ((FEC_CREACION >= @START_DATE AND FEC_CREACION < @END_DATE)
OR (FEC_REAL >= @START_DATE AND FEC_REAL < @END_DATE)
--

1. how to get around this?
2. if i've got to modify thr code to the sp, how can i modify it ?

id appreciate your help






No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

alejo46
Posting Yak Master

157 Posts

Posted - 2012-01-25 : 11:34:30
I TYPE THE PARENTHESIE AND YIELdS ME ANOTHER ERROR:

ERROR 156:Incorrect Synatax near the word DECLARE
Line 15: iIncorrect Synatax near the')'


CREATE PROCEDURE pr_inci
(
DECLARE @FECHA_INI VARCHAR(8)
DECLARE @FECHAFIN VARCHAR(8)
)

AS

SET NOCOUNT ON

--SET @FECHA_INI = '20120103'

--SET @FECHAFIN = '20120104'

SELECT CONVERT(VARCHAR(8),FEC_CREACION,112),COUNT(1) CANTIDAD
from ACA_INCIDENCIA

WHERE ((FEC_CREACION >= @FECHA_INI AND FEC_CREACION < @FECHAFIN)

OR (FEC_REAL >= @FECHA_INI AND FEC_REAL < @FECHAFIN)

OR (FEC_HISTORICO >= @FECHA_INI AND FEC_HISTORICO < @FECHAFIN ))

AND FUENTE=1

GROUP BY CONVERT(VARCHAR(8),FEC_CREACION,112)

ORDER BY CONVERT(VARCHAR(8),FEC_CREACION,112)


Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-25 : 11:55:29
you aren't specifying the params correctly.

Try:


CREATE PROCEDURE pr_inci(
@FECHA_INI DATE
, @FECHAFIN DATE
)
AS BEGIN

SET NOCOUNT ON

SELECT
CONVERT(VARCHAR(8),FEC_CREACION,112) AS [???]
,COUNT(1) AS CANTIDAD
FROM
ACA_INCIDENCIA
WHERE
(
( FEC_CREACION >= @FECHA_INI AND FEC_CREACION < @FECHAFIN )

OR ( FEC_REAL >= @FECHA_INI AND FEC_REAL < @FECHAFIN )

OR ( FEC_HISTORICO >= @FECHA_INI AND FEC_HISTORICO < @FECHAFIN )
)

AND FUENTE=1
GROUP BY
CONVERT(VARCHAR(8),FEC_CREACION,112)
END



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

alejo46
Posting Yak Master

157 Posts

Posted - 2012-01-26 : 15:10:28
OK, NOW ITS WORKING OK WITH THE CHANGES, THANK YOU VERY MUCH FOR YOUR HELP,
Go to Top of Page
   

- Advertisement -