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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:03:59+00:00 2026-06-12T01:03:59+00:00

I am writing a query that will be used in a .NET application, therefore

  • 0

I am writing a query that will be used in a .NET application, therefore I would like the SQL Server 2008 o do much of the processing for me instead of the client PC that the application will run on.

I am trying to get data from some tables I joined together.

Here is an example:

SELECT SUBSTRING(CAST(CAST(HCPD.SeferCikisZamani AS TIME) AS VARCHAR), 1, 5) AS Kalkis, SUBSTRING(CAST(CAST(HCPD.DonusZamani AS TIME) AS VARCHAR), 1, 5) AS Donus, V.AracPlaka
FROM HAT_CALISMA_PLANI HCP WITH(NOLOCK)
INNER JOIN HAT_CALISMA_PLANI_DETAY HCPD WITH(NOLOCK) ON HCPD.HatCalismaPlaniKey = HCP.HatCalismaPlaniKey
INNER JOIN VALIDATOR V WITH(NOLOCK) ON V.ValidatorKey = HCPD.ValidatorKey
WHERE HCP.HatKey = 2 AND CAST(HCPD.SeferCikisZamani AS DATE) = '2012-09-25'
ORDER BY Kalkis

This query returns this result:

Kalkis  Donus   AracPlaka
-------------------------
01:51   02:01   07 ABY 04
02:02   02:12   07 AB 978
02:21   02:31   07 ABY 04
02:32   02:42   07 AB 978
03:01   03:11   07 ABY 04
03:02   03:12   07 AB 978
03:31   03:41   07 ABY 04
03:42   03:52   07 AB 978
04:01   04:11   07 ABY 04

However, In my report they are supposed to look like this,

        07 ABY 04   07 AB 978
Kalkis  06:15       06:30
Donus   07:45       08:00
Kalkis  08:00       08:10
Donus   09:30       09:40
Kalkis  10:00       10:15
Donus   11:30       11:45
Kalkis  12:30       12:45
Donus   14:00       14:15

By the way, these are like bus schedules.
Anyone know a good way to achieve this?

  • 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-12T01:04:00+00:00Added an answer on June 12, 2026 at 1:04 am

    It would be easier to see the data before you queried it, but if you want to use your existing query, you can do the following:

    select *
    from
    (
      select AracPlaka, val, col,
         row_number() over(partition by AracPlaka order by VAL, col) rn
      from
      (
        SELECT SUBSTRING(CAST(CAST(HCPD.SeferCikisZamani AS TIME) AS VARCHAR), 1, 5) AS Kalkis, 
          SUBSTRING(CAST(CAST(HCPD.DonusZamani AS TIME) AS VARCHAR), 1, 5) AS Donus, 
          V.AracPlaka
        FROM HAT_CALISMA_PLANI HCP WITH(NOLOCK)
        INNER JOIN HAT_CALISMA_PLANI_DETAY HCPD WITH(NOLOCK) 
          ON HCPD.HatCalismaPlaniKey = HCP.HatCalismaPlaniKey
        INNER JOIN VALIDATOR V WITH(NOLOCK) 
          ON V.ValidatorKey = HCPD.ValidatorKey
        WHERE HCP.HatKey = 2 
          AND CAST(HCPD.SeferCikisZamani AS DATE) = '2012-09-25'
       -- ORDER BY Kalkis
      ) x
      unpivot
      (
        val
        for col in(Kalkis, Donus)
      ) u
    ) x1
    pivot
    (
      max(val)
      for AracPlaka In([07 ABY 04], [07 AB 978])
    ) p
    

    Since you are attempting to PIVOT two columns, the easiest way is to UNPIVOT the Kalkis and the Donus columns first, then apply the PIVOT to the data.

    Here is a SQL Fiddle with Demo (excludes your original query)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a query that will be used in a .NET application, therefore
Given a username, how would I go about writing an LDAP query that will
I need help writing a T-SQL query that will generate 52 rows of data
I will be writing an IOS app that will query data from a server.
How would one go about writing a query that selects items 2000-2010 out of
I'm writing a PHP script that builds an SQL query by concatenating the string
I am writing a simple data warehouse that will allow me to query the
I am in need of a scalable and performant HTTP application/server that will be
I need help writing a query that will validate a first expression and than,
I will be constructing an ecommerce site, and would like to use a no-sql

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.