Return 2 lines of text from a row

  • My SQL query is: SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='James'

    This pulls all the correct data back but my fault field does have alot of text in that record is there any way  i can limit the fault row text field to only pull 2 lines.
    From that field  only or am i looking at adjusting my php to do this?

    Thanks James

  • jamesstirling01 - Friday, May 11, 2018 9:01 AM

    My SQL query is: SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='James'

    This pulls all the correct data back but my fault field does have alot of text in that record is there any way  i can limit the fault row text field to only pull 2 lines.
    From that field  only or am i looking at adjusting my php to do this?

    Thanks James

    Not sure how you would define two lines but if you if you had a column named Fault and you only wanted the first 200 characters, you could do something like:
    SELECT LEFT(Fault, 200)
    FROM [JobInfo$]

    Sue

  • If you have line feeds in there, you can also use CHARINDEX/PATINDEX to search for those and then pull back the number of characters to one of those.

  • jamesstirling01 - Friday, May 11, 2018 9:01 AM

    My SQL query is: SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='James'

    This pulls all the correct data back but my fault field does have alot of text in that record is there any way  i can limit the fault row text field to only pull 2 lines.
    From that field  only or am i looking at adjusting my php to do this?

    Thanks James

    What do you mean by 2 lines? The amount of text that fits in 2 lines or the text before the second line feed? If it's the first case, would it be fine to show just a piece of the last word?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • jamesstirling01 - Friday, May 11, 2018 9:01 AM

    My SQL query is: SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='James'

    This pulls all the correct data back but my fault field does have alot of text in that record is there any way  i can limit the fault row text field to only pull 2 lines.
    From that field  only or am i looking at adjusting my php to do this?

    Thanks James

    Can you kindly post the sample data with desired output.

    Saravanan

  • Hi,
    Sorry for  the  late reply been away on holiday.

    The desired input would be  as follows

    Company A       11111
    Bob Green: My PC  doesnt boot the  error displayed is it has no system disk my PC booted fine yesterday.
    But you came out and looked at it  last week. If my PC needs returning to your repair center can you 
    configure me on another machine & setup my printer and RDP access please.

    The text in bold can be mutiple lines but i would only like to show 2 lines or a number of charactors rather than the full string is there anyway i can pull just the required DB rows and then use the LEFT statement on that field and leave the rest as default.

    Thanks  James

  • jamesstirling01 - Monday, May 21, 2018 5:13 AM

    Hi,
    Sorry for  the  late reply been away on holiday.

    The desired input would be  as follows

    Company A       11111
    Bob Green: My PC  doesnt boot the  error displayed is it has no system disk my PC booted fine yesterday.
    But you came out and looked at it  last week. If my PC needs returning to your repair center can you 
    configure me on another machine & setup my printer and RDP access please.

    The text in bold can be mutiple lines but i would only like to show 2 lines or a number of charactors rather than the full string is there anyway i can pull just the required DB rows and then use the LEFT statement on that field and leave the rest as default.

    Thanks  James

    Here's the problem.   Define a line.   Think in detail about how you were able to determine that there were "multiple lines".   Just because you "see" what appears to be multiple lines, doesn't necessarily mean that there actually ARE multiple lines.   How did you query the data?  What tool did you use?   What kind of application has this data?   it would appear to be a problem management system of some kind.   Such systems may or may not allow a new line to occur.   The only way to know for sure is to find the "line feed" character ( CHAR(10) ).embedded within the column's data.   You can use CHARINDEX or PATINDEX to find it.   If you aren't familiar with those SQL Server functions, look them up and find the MS documentation on them.   Also, fyi, new lines created on a Windows machine usually get two characters for the new line purpose - CHAR(13) and CHAR(10), usually in that order.   CHAR(13) is the "carriage return" character.   Carriage Return and Line Feed are ASCII characters that have been part of the standard going all the way back to the days of teletypes.  Back then you had to tell a teletype to return the carriage mechanism to the beginning of the line, and the tell it "line feed", which would then advance the paper by one line.   Let us know what you discover in that regard.

    The next question is: how do you plan to present the information?   What kind of mechanism will be used to display the information?   Sometimes, just the choice of tool determines how you might want to format the data.   In some tools, the data will automatically "wrap" at the end of a line.   This is part of why I asked about what tool you were using to actually "see" the data, because it may simply "wrap" the data, and thus the definition of a line is rather fluid, and will depend on font size, character widths, and the data itself, as to what fits on "one line".

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Basically the program i am desgining is a new SQL & PHP Job Logging System it was on and still is on a frontend backend DB built in Access.

    My program is built in PHP  and contacts my  SQL DB exported from the backend DB.

    My Job board which will be dispalyed on 2 screens so we can see allocated jobs. My SQL query selects * from job info

    My PHP is coded so it gets the Customer Name, Job Number and Fault ideally i would like to limit the amount of text shown on the Fault field so its not taking up so much space per record.

    I would also like to  pull back only 10 jobs per engineer so my lists dont overlap. Once i have the basics i can tweak to the required design.

    The problem is its all built from Access and i am trying to re-design and keep the system logical.

    Thanks for your help
    James

  • jamesstirling01 - Monday, May 21, 2018 8:19 AM

    Basically the program i am desgining is a new SQL & PHP Job Logging System it was on and still is on a frontend backend DB built in Access.

    My program is built in PHP  and contacts my  SQL DB exported from the backend DB.

    My Job board which will be dispalyed on 2 screens so we can see allocated jobs. My SQL query selects * from job info

    My PHP is coded so it gets the Customer Name, Job Number and Fault ideally i would like to limit the amount of text shown on the Fault field so its not taking up so much space per record.

    I would also like to  pull back only 10 jobs per engineer so my lists dont overlap. Once i have the basics i can tweak to the required design.

    The problem is its all built from Access and i am trying to re-design and keep the system logical.

    Thanks for your help
    James

    Haven't you ever used a text box control that has scroll bars?

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • In regards to the textbox with scroll bars, yes i have thought about using one but the job board is a static job list so engineers\managers can see there open jobs.
    No  engineers would be activley scrolling through  the jobs on that board its more a reference to whats open hence way i would like to limit the fault table.

  • Thanks for all the assistance i have sorted what i require.

    Thanks once again.

    James

  • jamesstirling01 - Monday, May 21, 2018 9:56 AM

    In regards to the textbox with scroll bars, yes i have thought about using one but the job board is a static job list so engineers\managers can see there open jobs.
    No  engineers would be activley scrolling through  the jobs on that board its more a reference to whats open hence way i would like to limit the fault table.

    Then my guess is to do it the way this forum lists topic titles...  Cut it off at a fixed number of characters and add the ellipsis (...).   At least that way, someone knows if there's more detail to be had.   Provide a link to the detail for that job and you're probably golden...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply