Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Stored procedure

Stored procedure

Scheduled Pinned Locked Moved ASP.NET
helpdatabasetutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.

    USE [reportserver]
    GO

    --Create the Procedure
    CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
    AS
    BEGIN
    IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
    BEGIN
    RETURN @RowCount = 'Exists'
    END
    ELSE
    BEGIN
    RETURN @RowCount = 'NotExists'
    END
    END

    but it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg

    R T 2 Replies Last reply
    0
    • M Morgs Morgan

      Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.

      USE [reportserver]
      GO

      --Create the Procedure
      CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
      AS
      BEGIN
      IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
      BEGIN
      RETURN @RowCount = 'Exists'
      END
      ELSE
      BEGIN
      RETURN @RowCount = 'NotExists'
      END
      END

      but it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Here's one way:

      USE [reportserver]
      GO

      --Create the Procedure
      CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10))
      AS
      BEGIN
      declare @RowCount varchar(10)

      IF EXISTS(SELECT \* FROM \[UserProfile\] WHERE \[userid\] = @userid)
      BEGIN
      	set @RowCount = 'Exists'
      END
      ELSE
      BEGIN
      	set @RowCount = 'NotExists'
      END
      
      select @RowCount as Counter
      

      END

      me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven

      M 1 Reply Last reply
      0
      • R R Giskard Reventlov

        Here's one way:

        USE [reportserver]
        GO

        --Create the Procedure
        CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10))
        AS
        BEGIN
        declare @RowCount varchar(10)

        IF EXISTS(SELECT \* FROM \[UserProfile\] WHERE \[userid\] = @userid)
        BEGIN
        	set @RowCount = 'Exists'
        END
        ELSE
        BEGIN
        	set @RowCount = 'NotExists'
        END
        
        select @RowCount as Counter
        

        END

        me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven

        M Offline
        M Offline
        Morgs Morgan
        wrote on last edited by
        #3

        Thanks man, that was great help

        1 Reply Last reply
        0
        • M Morgs Morgan

          Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.

          USE [reportserver]
          GO

          --Create the Procedure
          CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
          AS
          BEGIN
          IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
          BEGIN
          RETURN @RowCount = 'Exists'
          END
          ELSE
          BEGIN
          RETURN @RowCount = 'NotExists'
          END
          END

          but it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          I wouldn't use rowCount since it is a reserved word. Also I think you are making it more difficult on yourself by requiring hard coded strings. Hard coded strings for program control flow are bad. All you need is this: select count([userid]) from [userprofile] where [userid]=@userID Then in your C# you can just check for > 0.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups