Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:27:53+00:00 2026-06-10T06:27:53+00:00

I’m trying to pull the students that are tardy for the previous period from

  • 0

I’m trying to pull the students that are tardy for the previous period from our attendance database (SQL Server 2008). The period attendance is stored in ATT.A1, ATT.A2 ... ATT.A7. I want to schedule a job to run each hour, starting at 9am, and pull the tardy students, but I can’t figure out the code.

Here’s my code (pseudo-code):

Declare @Period varchar(6)
Set @Period = 'att.a' + Cast((DATENAME(hour, GETDATE()) - 8) as varchar(1))

Select SC, SN, DT, @Period as Period, ATT.A1
From ATT
Where SC = '9' and @Period = 'T' 
    and DT = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)

When I use this, I get no results. If I remove @Period = 'T' from the Where clause, I get the following:

9   5177    2012-08-24 00:00:00.000 att.a1  T
9   5211    2012-08-24 00:00:00.000 att.a1   
9   5225    2012-08-24 00:00:00.000 att.a1  T
9   5229    2012-08-24 00:00:00.000 att.a1  T
9   5235    2012-08-24 00:00:00.000 att.a1  V
9   5242    2012-08-24 00:00:00.000 att.a1  T
9   5268    2012-08-24 00:00:00.000 att.a1  

I know that when I use @Period in the SELECT statement and WHERE clause it’s using the literal string value of @Period, but I need it to use the value of @Period as Table.Column.

So, at 9:00 it will select from ATT.A1, 10:00 from ATT.A2 … 15:00 from ATT.A7 and each time compare whether ATT.A# = ‘T’

I hope that’s clear.

Thanks,
Anthony

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:27:54+00:00Added an answer on June 10, 2026 at 6:27 am

    Sql Server makes a distinction between a string containing a column name, and the column name itself, so you’ll either need to use dynamic sql, or a case statement to translate the string to the actual column name as illustrated below:

    Case Statement (I’d recommend this one):

    Select SC, SN, DT, @Period as Period, ATT.A1
    From ATT
    Where 
        SC = '9' 
        and DT = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
        and case @period
            when 'att.a1' then att.a1
            when 'att.a2' then att.a2
            when 'att.a3' then att.a3
            when 'att.a4' then att.a4
            when 'att.a5' then att.a5
            when 'att.a6' then att.a6
            when 'att.a7' then att.a7
        end = 'T'
    

    Dynamic Sql:

    Declare @sql varchar(max)
    Set @sql = '
        Select SC, SN, DT, @Period as Period, ATT.A1
        From ATT
        Where SC = '9' and ' + @Period + ' = ''T'' 
            and DT = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)'
    Exec(@sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.