Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2004
    Posts
    74

    Unanswered: Getting correct data from a table

    Hey,


    I have a temp table with a column of all the same number. When I run my select statement I need it to bring back all the other data and just the single instance of the column with all the same numbers. How would I do this in my select statement?

    For example, here is my table:

    Here 1 One
    There 1 Two
    Up 1 Three
    Down 1 Four
    Back 1 Five


    I need to bring back everything from column 1 and 3, but just the single instance of 1 from column 2 since it contains all the same number. All the data is collected in a single select statement.

    Any suggestions?

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    This sounds an awful lot like homework..

    What does the exact result set look like?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Can you post the URL of the assignment, or scan it in as a JPG file? It is tough for me to figure out exactly what your instructor wants you to do.

    -PatP

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Dudes, this guy is NOT a student. We're at the tail end of the semester, and by now a student would have a clearer idea of how a SELECT statement works.

    I think what we are dealing with here is and Access or Crystal Report developer who wants functionality similiar to the "hide duplicate values" options in those applications.

    Spence23: Microsoft SQL Server is NOT a reporting interface. And neither are Oracle, DB2, or other database engines, for that matter. Even the Access database engine is separate from its Form and Reporting functionality. They just happen to be bundled together.

    You cannot (easily) get your output to display in this format from SQL Server:

    Code:
    1	Here	One
    	There	Two
    	Up	Three
    	Down	Four
    	Back	Five
    This a matter of how the data is presented, and should be handled by your presentation interface (Access, Crystal, whatever).
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Dec 2004
    Posts
    74
    There is a temp table being created, similar to this:

    AverageDaystoFill---TargetDaysToFill---DelayTime-------TargetDelay
    ------2------------------2----------------12----------------7
    ------4------------------2----------------14----------------7
    ------4------------------2----------------15----------------7
    ------5------------------2----------------10----------------7


    I need to bring everything back from 'AverageDaystoFill' and 'DelayTime', but I only need to bring back one 2 from 'TargetDaystoFill' and one 7 from 'TargetDelay' since it is the same number throughout all the column. All this needs to be brought back in a single select statement.

    Any help?

  6. #6
    Join Date
    Dec 2004
    Posts
    74
    Actually right now I am working with SQL Reporting Services. I was given the task to fix up various reports and make new onea corresponding to user requests.

  7. #7
    Join Date
    Dec 2004
    Posts
    74
    Woops, same post.

  8. #8
    Join Date
    Dec 2004
    Posts
    74
    Hey blindman,

    If it is not easy to do what I am saying, is there a way to make the temp table only except just the single entry for what I am saying and then select the data from it?

    Thanks

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    If you have this in a TEMP table, you could set all the duplicated values to NULL except for the first row (according to whatever sort order you want).

    But this is NOT something that should be handled through SQL Server or the TSQL language. I'm not familiar with Reporting Services, but there ought to be a formatting option that would accomplish what you want.

    Again, I cannot recommend placing this logic in your stored proc, just as a matter of principle and best practices.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  10. #10
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    It's a presentation issue

    In Access you have the ability to "hide" duplicates.

    [gasp...shock...amazement]
    I have never used reporting services
    [/gasp...shock...amazement]

    But I would hazard a guess that it has the same capability.

    I would guess I could write some tsql code to do what you're asking, but that not where the problem lies...

    PLUS it would get pretty ugly
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  11. #11
    Join Date
    Feb 2004
    Posts
    78
    What you are asking really doesn't make much sense. If it all has to be in the same select , perhaps something like this will work for you:

    select distinct 'AvgDaystoFill' [Column], AverageDaystoFill [value] from tempTable
    union
    select distinct 'TargetDaystoFill' [Column], TargetDaystoFill from tempTable
    union
    select distinct 'DelayTime' [Column], DelayTime from tempTable
    union
    select distinct 'TargetDelay' [Column], TargetDelay from tempTable

    Eric

  12. #12
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •