Niyoko
Niyoko

Reputation: 7672

Convert syntax in sql server

What's wrong with these statement?

ALTER PROCEDURE [cfg].[SetBooleanConfiguration]
@key varchar(50),
@value bit
AS
BEGIN

    exec cfg.SetConfiguration @key=@key, @datatype='Boolean', @value=CONVERT(varchar(4000),@value)

END

According to MSDN, I am sure CONVERT syntax is written well. But SSMS complain that there is incorrect syntax near CONVERT. What's wrong?

EDIT:

Statement below run well:

exec cfg.SetConfiguration @key='aa', @datatype='Boolean', @value='1'

But, statement below gives me error:

exec cfg.SetConfiguration @key='aa', @datatype='Boolean', @value=CONVERT(varchar(4000),1)

Upvotes: 0

Views: 408

Answers (2)

Mate
Mate

Reputation: 5274

Try this

ALTER PROCEDURE [cfg].[SetBooleanConfiguration]
@key varchar(50),
@value bit
AS
BEGIN
    DECLARE @convertedValue varchar(1)

    SET @convertedValue=CONVERT(varchar(1),@value)

    exec cfg.SetConfiguration @key=@key, @datatype='Boolean', @value=@convertedValue

END 

Upvotes: 1

Krishnanunni Jeevan
Krishnanunni Jeevan

Reputation: 1759

The datatype for @value is bit?Are you trying to Convert it to varchar(4000)?

Upvotes: 1

Related Questions