Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    133

    Unanswered: Niewbie: accept the input parameter of astring type

    Very simple problem but I still can not sovle, could you help me?
    I have a following store procedure:

    create procedure countauthors @state as
    declare @countauthors int
    select @countauthors=count(*) from authors
    where state=@state
    return @countauthors

    declare @result int
    exec @result=countauthors'ca'


    But it don't work for me. Is something wrong here?
    many thanks

  2. #2
    Join Date
    Aug 2004
    Posts
    10
    wrong syntax. you must declare the types for stored procedure parameters data types.

    try this:

    create procedure countauthors @state char(3)
    as
    declare @countauthors int
    select @countauthors=count(*) from authors
    where state=@state
    return @countauthors

    hth,
    Cristian Babu

  3. #3
    Join Date
    May 2004
    Posts
    133
    I'll try it now. thanks

  4. #4
    Join Date
    May 2004
    Posts
    133
    I tried this and it was ok.
    Then I typed:
    declare @result int
    exec @result=countauthors('CA')

    in order to find out the number of authors that are living in california.
    But new problem occured:
    "Server: Msg 170, Level 15, State 1, Line 2
    Line 2: Incorrect syntax near 'CA'."

    How can I solve this problem?
    many thanks.

  5. #5
    Join Date
    Sep 2004
    Posts
    4
    hi,
    you dont need brackets to pass parameters.
    try this.
    declare @result int
    exec @result=countauthors 'CA'
    select @result

    you will see the result on the QA.

    Cheers
    Andy

  6. #6
    Join Date
    May 2004
    Posts
    133
    many thanks. finally it woks for me.
    I do hope receive your replies when I post many many questions here. Your replies are very useful for me.
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •