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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Getting the right sysntax for this.

Getting the right sysntax for this.

Scheduled Pinned Locked Moved Database
databaseregexhelpquestion
3 Posts 3 Posters 1 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.
  • R Offline
    R Offline
    Rudyvb08
    wrote on last edited by
    #1

    Hello all! This seems pretty simple, but I'm still stuck. Probably making it more complicated than it is. I have a tblPot, with Monday, Tuesday, etc as Columns. I need to return the Pot of the week based on todays date. I'm getting the day of the week from SQL with the DATENAME function. But how can I pass that to match the column name. Basicly I need this simple statement. SELECT Potname FROM tblPot WHERE Monday = 'true' How can I get it so it grabs the current day automaticly. Thanks! Rudy :-D here is the code

    ALTER PROCEDURE [dbo].[SchedPod]
    -- Add the parameters for the stored procedure here

    @Day nvarchar(50) Output,
    @PotList nvarchar(50) OUTPUT

    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    

    select @Day = DATENAME(dw , getDate())

    SELECT @Potlist =  PotName
    

    FROM tblPot
    WHERE (@Day = 'true')

    END

    E M 2 Replies Last reply
    0
    • R Rudyvb08

      Hello all! This seems pretty simple, but I'm still stuck. Probably making it more complicated than it is. I have a tblPot, with Monday, Tuesday, etc as Columns. I need to return the Pot of the week based on todays date. I'm getting the day of the week from SQL with the DATENAME function. But how can I pass that to match the column name. Basicly I need this simple statement. SELECT Potname FROM tblPot WHERE Monday = 'true' How can I get it so it grabs the current day automaticly. Thanks! Rudy :-D here is the code

      ALTER PROCEDURE [dbo].[SchedPod]
      -- Add the parameters for the stored procedure here

      @Day nvarchar(50) Output,
      @PotList nvarchar(50) OUTPUT

      AS
      BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      -- Insert statements for procedure here
      

      select @Day = DATENAME(dw , getDate())

      SELECT @Potlist =  PotName
      

      FROM tblPot
      WHERE (@Day = 'true')

      END

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      Unfortunately the table definition you have makes it quite difficult to get the result you want based on the current day. However, after saying that there is still a solution to use UNPIVOT. The idea is to change your day columns (Monday, Tuesday) to a row value, then query the result of the UNPIVOT. See UNPIVOT[^]

      "A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin Edbert Sydney, Australia

      1 Reply Last reply
      0
      • R Rudyvb08

        Hello all! This seems pretty simple, but I'm still stuck. Probably making it more complicated than it is. I have a tblPot, with Monday, Tuesday, etc as Columns. I need to return the Pot of the week based on todays date. I'm getting the day of the week from SQL with the DATENAME function. But how can I pass that to match the column name. Basicly I need this simple statement. SELECT Potname FROM tblPot WHERE Monday = 'true' How can I get it so it grabs the current day automaticly. Thanks! Rudy :-D here is the code

        ALTER PROCEDURE [dbo].[SchedPod]
        -- Add the parameters for the stored procedure here

        @Day nvarchar(50) Output,
        @PotList nvarchar(50) OUTPUT

        AS
        BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;

        -- Insert statements for procedure here
        

        select @Day = DATENAME(dw , getDate())

        SELECT @Potlist =  PotName
        

        FROM tblPot
        WHERE (@Day = 'true')

        END

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Use a case statement

        Select @PotName = Case DATENAME(dw , getDate()) When 1 then MondayCol
        when 2 then TusedayCol End
        from tblPot

        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