How to intialize varchar type in stored procedure [Resolved]

Posted by Amritha444 under Sql Server on 8/30/2010 | Points: 10 | Views : 5542 | Status : [Member] | Replies : 2
DECLARE variable_name datatype(size) DEFAULT default_value;
here i want to intialize datatype varchar to default value yes
i tried two methods
first one
DECLARE n_status VARCHAR(10) DEFAULT yes;

second
DECLARE n_status VARCHAR(10);
set n_status=yes;
also
set n_status='yes';
But showing error.
How to correct this
Thanks in Advance




Responses

Posted by: Shankul2784 on: 8/30/2010 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi

try this-

DECLARE
n_status VARCHAR(10)
set n_status = 'yes'

Thanks & Regards,

Shailesh

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 8/30/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

A.Normal Script
In SQL Server 2008/2008 R2 onwards :
DECLARE @A VARCHAR(5) = 'YES'

In SQL Server 6.5/7/2000/2005
DECLARE @A VARCHAR(5)
SET @A = 'YES'
--Or
SELECT @A = 'YES'


B.Using Stored Procedure:(It supports in all version of SQL Server)
CREATE PROC USP_Proc1

(
@Parameter1 VARCHAR(5) = 'YES'
)
AS
BEGIN
SET NOCOUNT ON
SELECT @Parameter1 'Parameter1'
END
GO
Not passing any value:
EXEC USP_Proc1
Result:

Parameter1
YES

Passing value:
EXEC USP_Proc1 'NO'
Result:

Parameter1
NO

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response