SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


create procedure gets stuck on select


create procedure gets stuck on select

Author
Message
Senchi
Senchi
Right there with Babe
Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)

Group: General Forum Members
Points: 751 Visits: 72
CREATE PROCEDURE sp_cenik 
as begin

DECLARE
@OD DATETIME,
@DO DATETIME,
@TipSobe VARCHAR(6),
@KodaCenika INT,
@Sezona INT

SELECT
@Od = :a2,
@Do = :a3,
@TipSobe = :a1,
@KodaCenika = :a4;


I get:
"Msg 102, Level 15, State 1, Procedure sp_cenik, Line 18
Incorrect syntax near ':'.

What am I doing wrong ? These are parameters.

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)SSC Guru (818K reputation)

Group: General Forum Members
Points: 818097 Visits: 46332
Senchi - Tuesday, January 2, 2018 7:19 PM
CREATE PROCEDURE sp_cenik 
as begin

DECLARE
@OD DATETIME,
@DO DATETIME,
@TipSobe VARCHAR(6),
@KodaCenika INT,
@Sezona INT

SELECT
@Od = :a2,
@Do = :a3,
@TipSobe = :a1,
@KodaCenika = :a4;


I get:
"Msg 102, Level 15, State 1, Procedure sp_cenik, Line 18
Incorrect syntax near ':'.

What am I doing wrong ? These are parameters.


If they are, in fact, parameters as you say, then that's the wrong way to pass parameters in a stored procedure. Please see the following...
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql

Parameters look like variables that begin with @.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Senchi
Senchi
Right there with Babe
Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)

Group: General Forum Members
Points: 751 Visits: 72
DECLARE
@OD DATETIME,
@DO DATETIME,
@TipSobe VARCHAR(6),
@KodaCenika INT,
@Sezona INT,

@p1 DATETIME,
@p2 DATETIME,
@p3 VARCHAR(6),
@p4 INT


SELECT
@Od = @p1, @Do = @p2, @TipSobe =@p3, @KodaCenika = @p4


so this would be the way to go ...?

pietlinden
pietlinden
SSC-Forever
SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)SSC-Forever (49K reputation)

Group: General Forum Members
Points: 49763 Visits: 16222
Could you explain what this does? (Is this Oracle?)
SELECT
@Od = :a2,
@Do = :a3,
@TipSobe = :a1,
@KodaCenika = :a4;

Senchi
Senchi
Right there with Babe
Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)Right there with Babe (751 reputation)

Group: General Forum Members
Points: 751 Visits: 72
this is sql server 2014 and those are parameters I supply within my application.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)

Group: General Forum Members
Points: 860378 Visits: 48577
No, that's declaring variables. (and no idea what the unknown language is doing)

Please have a look at the T-SQL documentation for creating procedures: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)

Group: General Forum Members
Points: 340103 Visits: 34009
Senchi - Tuesday, January 2, 2018 7:19 PM
CREATE PROCEDURE sp_cenik 
as begin

DECLARE
@OD DATETIME,
@DO DATETIME,
@TipSobe VARCHAR(6),
@KodaCenika INT,
@Sezona INT

SELECT
@Od = :a2,
@Do = :a3,
@TipSobe = :a1,
@KodaCenika = :a4;


I get:
"Msg 102, Level 15, State 1, Procedure sp_cenik, Line 18
Incorrect syntax near ':'.

What am I doing wrong ? These are parameters.


So, the error message says that your syntax is messed up at the colon, this thing, : . You have colons on your code. T-SQL doesn't use colons in syntax like that. This is why everyone is having a hard time helping.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search