Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2006, 04:17 AM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with PRINT MS-SQL 2005

PRINT from TRANSACT-SQL with MS-SQL 2005 shows no message on the client :(

 
Old November 7th, 2006, 10:38 AM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Can you provide a bit more information? I use PRINT all the time and it works...

How are you using it and what are you tring to do?


Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
 
Old August 13th, 2007, 08:41 PM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Scott,

     I was having this problem and found your comment through google. I think I know what our German friends were experiencing and if not, at least we have a documented case of the print command not executing in ms sql 2005. Below is the code where the print command did not function and did not send anything to the client. In the code below the prints of the grand totals after the cursor is closed were not printing at all. Some of the subtotals were not printing also. The problem is doing math operations on a null field. For some reason when the math is done on a null field the print command refuses to execute. In many cases it shows no error message, the print command just does not execute. As I worked to shake this problem lose, I did get a "Domain Error" message on one iteration. That is what lead me to the null conclusion. When I removed all the nulls from the fields involved in the math commands it started to run perfectly. It's a little lame of MS to not print some kind of error message on the null operation or at least say that it could not execute the print command. This was a small table on a $50 personal copy of ms sql 2005. So in this case isnull(xxx,0) was the answer.

                     ... Flash Gordon


BEGIN
    declare @xTotPaid decimal(14,2), @xTotCurrVal decimal(14,2),
    @xDaysDiff decimal(10,1), @xpr decimal (10,1), @xCat char(15),
    @xPrior char(15), @xSymbol char(10),
    @xSubTotPaid decimal(14,2),
    @xSubTotCurr decimal(14,2),
    @xGrdTotPaid decimal(14,2),
    @xGrdTotCurr decimal(14,2), @xGain decimal(14,2),
    @xprin varchar(133), @xcompnm char(40),
    @xprin2 varchar(133)

    set @xSubTotPaid = 0
    set @xSubTotCurr = 0
    set @xGrdTotPaid = 0
    set @xGrdTotCurr = 0

    declare inv_cursor cursor for

    select primarycat,
           symbol,
           companyname,
           totbuyprice,
           totcurrvalue,
           convert(decimal, (datediff(day,buydate,getdate())))
    from portfolio
    order by primarycat, companyname

    open inv_cursor

    FETCH NEXT FROM inv_cursor
    into @xCat, @xsymbol, @xcompnm, @xtotpaid, @xtotcurrval, @xdaysdiff

    set @xprior = @xcat
    set @xtotpaid = case when @xtotpaid = 0 then 1 else @xtotpaid end

    while @@FETCH_STATUS = 0
    BEGIN

      if @xprior = @xcat
      BEGIN
        -- regular processing logic
        set @xpr = @xdaysdiff/365
        --set @xgain = (((@xtotcurrval/@xtotpaid)-1)*100) / @xpr
        set @xprin = @xcat + ' ' + @xsymbol + ' ' + @xcompnm + ' '
          + convert(varchar,cast(@xtotpaid as money),1)+ ' '
          + convert(varchar,cast(@xtotcurrval as money),1) + ' '
          + convert(varchar, (dbo.fn_ComputeReturn(@xtotpaid,@xtotcurrval,@xday sdiff))) + '% '
          + convert(varchar,@xpr)
        print @xprin
      END
      ELSE
      BEGIN
        -- control break logic
        print ' '
        set @xprin = 'SubTotal for: ' + @xprior + ' Is: '
          + convert(varchar,cast(@xsubtotpaid as money),1) + ' '
          + convert(varchar,cast(@xsubtotcurr as money),1)
        print @xprin
        print ' '
        set @xsubtotcurr = 0
        set @xsubtotpaid = 0
        set @xpr = @xdaysdiff/365
        --set @xgain = (((@xtotcurrval/@xtotpaid)-1)*100) / @xpr
        -- print the first line of the next set or it drops
        set @xprin = @xcat + ' ' + @xsymbol + ' ' + @xcompnm + ' '
          + convert(varchar,cast(@xtotpaid as money),1)+ ' '
          + convert(varchar,cast(@xtotcurrval as money),1) + ' '
          + convert(varchar, (dbo.fn_ComputeReturn(@xtotpaid,@xtotcurrval,@xday sdiff))) + '% '
          + convert(varchar,@xpr)
        print @xprin
      END
      set @xsubtotcurr = @xsubtotcurr + @xtotcurrval
      set @xsubtotpaid = @xsubtotpaid + @xtotpaid
      set @xgrdtotcurr = @xgrdtotcurr + @xtotcurrval
      set @xgrdtotpaid = @xgrdtotpaid + @xtotpaid
      set @xprior = @xcat
      FETCH NEXT FROM inv_cursor
      into @xCat, @xsymbol, @xcompnm, @xtotpaid, @xtotcurrval, @xdaysdiff
    END
      close inv_cursor
      deallocate inv_cursor
      -- print final subtotal
      --set @xprin2 = convert(varchar, @xgrdtotcurr)
      --print ' final total ' + @xprior + ' '
      -- loses its mind from this point on, won't print any more

      --+ convert(varchar,@xsubtotcurr)+ ' '
      --+ convert(varchar, @xsubtotcurr)
      --print ' '
      --print ' Grand Total is '
      --+ convert(varchar, @xgrdtotpaid) + ' '
      --+ convert(varchar, @xgrdtotcurr)
      print ' '
      set @xprin2 = 'SubTotal for: ' + @xprior + ' Is: '
          + convert(varchar,cast(@xsubtotpaid as money),1) + ' '
          + convert(varchar,cast(@xsubtotcurr as money),1)
        print @xprin2
      print ' '
      set @xprin = ' Grand Total Is: '
          + convert(varchar,cast(@xgrdtotpaid as money),1) + ' '
          + convert(varchar,cast(@xgrdtotcurr as money),1)
      print @xprin
      --set @xprin = ' Grand Total Is: '
      -- + convert(varchar,cast(@xgrdtotpaid as money),1) + ' '
      -- + convert(varchar,cast(@xgrdtotcurr as money),1)
      --print @xprin
      -- final total current value
      --exec investments.dbo.grandtotal
END






Similar Threads
Thread Thread Starter Forum Replies Last Post
MS ACCESS 2003 FRONTEND AND MS SQL SERVER 2005 DB mohankumar0709 SQL Server 2005 3 March 23rd, 2007 12:48 AM
Ms Access 2003 and SQL 2005 micdev SQL Server 2005 1 March 22nd, 2007 02:50 PM
Converting from MS SQL 2005 to Sql Epress edition saif44 SQL Language 0 February 16th, 2007 04:17 PM
SQL Server 2005, SP 2 Install Problems kwilliams SQL Server 2005 1 December 1st, 2006 04:12 PM
Printdialog MS V.S. 2005, what to print Turbovulc General .NET 0 July 11th, 2006 02:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.