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 6678661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:16:10+00:00 2026-05-26T04:16:10+00:00

I have the following query: Declare @cnt as int Declare @int as int Set

  • 0

I have the following query:

Declare @cnt as int
Declare @int as int
Set @int = 0
Select @cnt =COUNT(Date) FROM tmp
While @int < @cnt 
Begin


    If (Select Datepart(MM,Start_Time) from dbo.tmp)>='00' and (Select Datepart(MM,Start_Time) from dbo.tmp)<'15'
        Set tmp.Start_Int = Datepart(HH,Start_Time)+'00'

    else If (Select Datepart(MM,Start_Time) from dbo.tmp)>='15' and (Select Datepart(MM,Start_Time) from dbo.tmp)<'30'
        Set tmp.Start_Int = Datepart(HH,Start_Time)+'15'

    else If (Select Datepart(MM,Start_Time) from dbo.tmp)>='30' and (Select Datepart(MM,Start_Time) from dbo.tmp)<'45'
        Set tmp.Start_Int = Datepart(HH,Start_Time)+'30'

    else If (Select Datepart(MM,Start_Time) from dbo.tmp)>='45' and (Select Datepart(MM,Start_Time) from dbo.tmp)<='59'
        Set tmp.Start_Int = Datepart(HH,Start_Time)+'45'
    end

As you can see, I am trying to update Start_Int to its proper intervals depending on where it falls. Using this, I get an error saying Incorrect syntax near ‘.’. I can assume this query is incorrect, but I cannot find any examples of a while query that uses a select to update a field if a condition is met.

  • 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-05-26T04:16:10+00:00Added an answer on May 26, 2026 at 4:16 am

    The errors are thrown by the tmp.Start_Int declarations, which I think you are trying to insert values into a database table called tmp.

    You need to change:

    Set tmp.Start_Int = Datepart(HH,Start_Time)+'00'
    

    to be something like:

    update dbo.tmp set tmp.Start_Int = Datepart(HH,Start_Time)+'00' 
    

    Also you might want to consider using a cursor to read through your data.

    EDIT

    Could you use the following as a basis?

    declare @tmp table (Start_Time datetime)
    
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:02')
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:12')
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:22')
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:32')
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:42')
    insert into @tmp (Start_Time) values ('1-Oct-2011 21:52')
    
    select 
    Start_Time, 
    (case 
        when Datepart(MI,Start_Time) > 0 and datepart(MI, Start_Time) < 15 
            then cast(Datepart(HH,Start_Time) as varchar(5))+'00'
        when Datepart(MI,Start_Time) > 15 and datepart(MI, Start_Time) < 30 
                then cast(Datepart(HH,Start_Time) as varchar(5))+'15'
        when Datepart(MI,Start_Time) > 30 and datepart(MI, Start_Time) < 45 
                then cast(Datepart(HH,Start_Time) as varchar(5))+'30'
        when Datepart(MI,Start_Time) > 45  
                then cast(Datepart(HH,Start_Time) as varchar(5))+'45'
    end) as Start_Int
    from @tmp
    

    Returns

    Start_Time              Start_Int
    ----------------------- ---------
    2011-10-01 21:02:00.000 2100
    2011-10-01 21:12:00.000 2100
    2011-10-01 21:22:00.000 2115
    2011-10-01 21:32:00.000 2130
    2011-10-01 21:42:00.000 2130
    2011-10-01 21:52:00.000 2145
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following query: DECLARE @IsStocked bit SELECT * FROM Products p WHERE
I have the following SQL query: Declare @Total_SysDown as int, @Login_SysDown as int Set
I have the following query: DECLARE @Region VARCHAR(MAX) SET @Region = '' SELECT @Region
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have the following query: SELECT rowid FROM table1 ORDER BY RANDOM() LIMIT 1
I have the following query SELECT e.topicShortName, d.catalogFileID, e.topicID FROM catalog_topics a LEFT JOIN
I have the following query: DECLARE @str VARCHAR(500) SET @str = 'Barcode: 22037 CaseSize:
I have the following query DECLARE @ProductIdsToExclude nvarchar(max) SET @ProductIdsToExclude = '49506541-4CE2-40AC-812A-7AB262E6F0B0,49506541-4ce2-40ac-812a-7ab262e6f0b0' I'm then
I have the following query: DECLARE @sync_table_name nvarchar(500) SET @sync_table_name = 'ContactTypes' DECLARE @sync_batch_size

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.