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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:24:17+00:00 2026-05-11T16:24:17+00:00

i need this table look please TABLE2 Table1 VisitingCount Date 1——————-15:09 3——————-15:10 7——————-15:15 1——————-15:39

  • 0

i need this table look please TABLE2


Table1

VisitingCount Date
1——————-15:09
3——————-15:10
7——————-15:15
1——————-15:39
2——————-15:40
3——————-15:47


How can i change this table below table


Table2

VisitingCount Date
11——————-15:00-15:30
6——————-15:30-16:00

so, i writed some sql user-defined functions look below please:

create FUNCTION [dbo].[fn_GetActivityLogsArranger]
(
@time AS nvarchar(max)
)

RETURNS  nvarchar(max)
AS
BEGIN
declare @Return varchar(30)

select @Return = case 
when @time between '00:00' and '00:30' then '00:00-00:30'
when @time between '00:30' and '01:00' then '00:30-01:00'
when @time between '01:00' and '01:30' then '01:00-01:30'

when @time between '01:30' and '02:00' then '01:30-02:00' 
when @time between '02:00' and '02:30' then '02:00-02:30' 
when @time between '02:30' and '03:00' then '02:30-03:00' 
when @time between '03:00' and '03:30' then '03:00-03:30' 
when @time between '03:30' and '04:00' then '03:30-04:00' 
when @time between '04:00' and '04:30' then '04:00-04:30' 
when @time between '04:30' and '05:00' then '04:30-05:00' 
when @time between '05:00' and '05:30' then '05:00-05:30'

when @time between '05:30' and '06:00' then '05:30-06:00' 
when @time between '06:00' and '06:30' then '06:00-06:30' 
when @time between '06:30' and '07:00' then '06:30-07:00' 
when @time between '07:00' and '07:30' then '07:00-07:30' 
when @time between '07:30' and '08:00' then '07:30-08:00' 
when @time between '08:00' and '08:30' then '08:00-08:30' 
when @time between '08:30' and '09:00' then '08:30-09:00' 
when @time between '09:00' and '09:30' then '09:00-09:30'

when @time between '09:30' and '10:00' then '09:30-10:00' 
when @time between '10:00' and '10:30' then '10:00-10:30' 
when @time between '10:30' and '11:00' then '10:30-11:00' 
when @time between '11:00' and '11:30' then '11:00-11:30' 
when @time between '11:30' and '12:00' then '11:30-12:00' 
when @time between '12:00' and '12:30' then '12:00-12:30' 
when @time between '12:30' and '13:00' then '12:30-13:00' 
when @time between '13:00' and '13:30' then '13:00-13:30'


when @time between '13:30' and '14:00' then '13:30-14:00' 
when @time between '14:00' and '14:30' then '14:00-14:30'
when @time between '14:30' and '15:00' then '14:30-15:00'
when @time between '15:00' and '15:30' then '15:00-15:30'
when @time between '15:30' and '16:00' then '15:30-16:00'
when @time between '16:00' and '16:30' then '16:00-16:30'
when @time between '16:00' and '16:30' then '16:00-16:30' 
when @time between '16:30' and '17:00' then '16:30-17:00' 
when @time between '17:00' and '17:30' then '17:00-17:30' 
when @time between '17:30' and '18:00' then '17:30-18:00'
when @time between '18:00' and '18:30' then '18:00-18:30' 


when @time between '18:30' and '19:00' then '18:30-19:00'
when @time between '19:00' and '19:30' then '19:00-19:30'
when @time between '19:30' and '20:00' then '19:30-20:00'
when @time between '20:00' and '20:30' then '20:00-20:30'
when @time between '20:30' and '21:00' then '20:30-21:00'
when @time between '21:00' and '21:30' then '21:00-21:30'
when @time between '21:30' and '22:00' then '21:30-22:00'
when @time between '22:00' and '22:30' then '22:00-22:30'
when @time between '22:30' and '23:00' then '22:30-23:00'
when @time between '23:00' and '23:30' then '23:00-23:30'
when @time between '23:30' and '24:00' then '23:30-:24:00'

else 'Unknown'
end
 Return @Return
end
 


So, i called this UDF in my sql query. So Result is correct.


select Count(Page) as VisitingCount,[Time]
from
( SELECT Page,Date,[user],
        dbo.fn_GetActivityLogsArranger(CONVERT(VARCHAR(5),Date, 108)) as [Time]
        FROM scr_SecuristLog
) scr_SecuristLog
where
        Date between '2009-05-06' and '2009-05-07'
and
        [user] in
(       select USERNAME
        from scr_CustomerAuthorities
        where customerID=Convert(varchar,4)
        and ID=Convert(varchar,43)
)
group by [Time] order by [Time] asc 

dbo.fn_GetActivityLogsArranger(CONVERT(VARCHAR(5),Date, 108))… function method is not effective method.
Because; writing too many “when-then” comparission is not sufficient way to take data.
Is there any method like: “Math.Round()” in sql not C#.

For Example:

Run(11:28) result: 11:00 but Run(11:31) Result: 12:00

  • 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-11T16:24:18+00:00Added an answer on May 11, 2026 at 4:24 pm

    I recommend you look at my response on your previous thread, but this seems to work:

    declare @t datetime
    set @t = '2009-05-06 12:29.997'
    --truncate anything smaller than minute
    set @t = cast (@t as smalldatetime)
    select @t
    select 
        case
            when datepart(minute, @t) >= 30
                then dateadd(minute, 60-(datepart(minute, @t)), @t)
            else dateadd(minute, -(datepart(minute, @t)), @t)
        end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To better explain what I need please look at this table: ID --- image
Please take a look at this picture: You can see a QTableView with some
i need to do this : There is a table called table1 it has
i need to do this : There is a table called table1 it has
I need to change table name from lowercase to uppercase but using this statement
look at this table please table |id| |name| |order| i must get the rows,
If you will look at the image above. I need to update this table
if i use this query thath creates a table(look Table1), But VisitingGap column is
This question is not about caching. I need this in-memory table for many small
I need my QT application to create a table and copy this table into

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.