Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Printing Reports

Printing Reports

Scheduled Pinned Locked Moved Database
databasehelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OMalleyW
    wrote on last edited by
    #1

    Hello, We have several reports on the web that require printing. Now as I am sure all of you know it can be a pain to write all the code required to format the lines correctly so they dont wrap. There is one report that I am thinking of that has caused me much pain in the past. It prints out all the operations and instructions to create a part. Well the operation descriptions can be quite long so I needed a way to accuratly print and count lines of text. I had written a class that would formatt the information breaking at the correct length for printing but the problem was the ammount of time it was costing me when the report would render. So I thought to my self.. Self.. wouldn't it be great if I had a function that would formatt the information for me so when I pulled it from the database all I had to do was display and count? So I wrote a little function that does just that: --------------------------------------------------------------------------- CREATE FUNCTION F_FormatRevisionDescForPrint(@Desc VARCHAR(1000), @DisplayLenghOfString INT) RETURNS VARCHAR(2000) AS BEGIN DECLARE @CharacterCounter INT ,@DescLen INT ,@WhenToBreak INT ,@FormattedDesc VARCHAR(2000) ,@NewLine VARCHAR(2) ,@Space VARCHAR(1) ,@NextCharacter VARCHAR(1) ,@PreviousCharacter VARCHAR(1) ,@CurrentCharacter VARCHAR(1) ,@NewString VARCHAR(2000) ,@NumberOfCharactersToCut INT -- SELECT @CharacterCounter = 0 ,@DescLen = LEN(@Desc) ,@WhenToBreak = 0 ,@FormattedDesc = '' ,@NewString = '' ,@NewLine = CHAR(13) + CHAR(10) ,@Space = ' ' -- IF (@DescLen > 0) BEGIN WHILE @CharacterCounter <= @DescLen BEGIN -- SELECT @FormattedDesc = @FormattedDesc + SUBSTRING(@Desc,@CharacterCounter,1) ,@CurrentCharacter = SUBSTRING(@Desc,@CharacterCounter,1) ,@NextCharacter = SUBSTRING(@Desc,(@CharacterCounter+1),1) ,@PreviousCharacter = SUBSTRING(@Desc,(@CharacterCounter-1),1) ,@WhenToBreak = @WhenToBreak + 1 -- IF (@WhenToBreak = @DisplayLenghOfString) BEGIN -- I need to check and make sure that I am not breaking on -- a word. IF (@CurrentCharacter = @Space) BEGIN -- There is a space here so it is ok to break -- I know that I am not in the middle of a word SELECT @FormattedDesc = @FormattedDesc + '' ,@WhenToBreak = 0 ,@CharacterCounter = @CharacterCounter + 1 -- END ELSE IF (@CurrentCharacter != @Space) BEGIN -- houston we have a problem I am somewher

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups