Showing posts with label sqlshots. Show all posts
Showing posts with label sqlshots. Show all posts

sqlshots: Add Leading Zeros

Typically in most cases you find yourself removing leading zeros but in this case I needed to add leading zeros to a column. 

Remove Leading Zeros

SELECT CAST(CAST(ColumnName AS INT) AS VARCHAR(10)) FROM TableName

Let's Pad the field

Since I needed 6 chars this will add 3 spaces to the front of the numbers

SELECT STR(ColumnName, 6) FROM TableName

Add Leading Zeros

Let's say we need to add zeros to an employee id, well this would be an easy way to accomplish it.

SELECT REPLACE(STR(ColumnName, 6), SPACE(1), '0') FROM TableName

SELECT SalesPersonID       ,REPLACE(STR(SalesPersonID, 6), SPACE(1), '0') AS PaddedSalesPID FROM   Sales.SalesPerson

Note: the SPACE(1) is equivalent to ' ' (That is a Tick Space Tick) So two Ticks with a space in between)

Update Table

UPDATE Sales.SalesPerson SET newSalesPID = REPLACE(STR(SalesPersonID, 6), SPACE(1), '0')

Posted via email from wetmatter nonsense

sqlshots: What version are you running?

1. This option is okay but not what I needed.

SELECT @@VERSION AS [Version Info]

2. This option is okay as well but does not indicate if it is 2000, 2005, 2008. Yeah it shows the product version number, but if you don't readily know it then you have to look it up.

SELECT SERVERPROPERTY('productversion')  AS [Version]         ,SERVERPROPERTY('edition')            AS [Edition]         ,SERVERPROPERTY('productlevel')     AS [Service Pack]

3. This option works okay but the you'll have issues with the Edition as the char length will differ

SELECT RIGHT(LEFT(@@VERSION,25),15)  AS [Product]        ,RIGHT(LEFT(@@VERSION,40),12) AS [Product Version]         ,LEFT(RIGHT(@@VERSION,65),17) AS [Edition]          ,SERVERPROPERTY('productlevel')  AS [Service Pack]

4. This is the winner for now (not great for version 6.5 & 7 as some additional char proceeds after due to the char length) 

SELECT RIGHT(LEFT(@@VERSION,25),15)    AS [Product]       ,RIGHT(LEFT(@@VERSION,40),12)   AS [Product Version]       ,SERVERPROPERTY('edition')      AS [Edition]       ,SERVERPROPERTY('productlevel') AS [Service Pack]

5. After some thought I like this route better

SELECT RIGHT(LEFT(@@VERSION,25),15)    AS [Product]    ,SERVERPROPERTY('productversion')   AS [Version]    ,SERVERPROPERTY('edition')          AS [Edition]    ,SERVERPROPERTY('productlevel')     AS [Service Pack]

I haven't tried this with any other version other than 2005, but I suspect 2000 & 2008 will work just fine. Earlier versions like 6.5 & 7 I am not sure of.

Posted via web from wetmatter nonsense

sqlshots: Reporting Services 2005 - Unable to load client print control

I received a trouble support call from a client that encountered an error while attempting to print a Report via Reporting Services. The client was able to print before then suddenly it became an issue. Coincidentally Microsoft released two hotfixes (KB956803 & KB956391) which added a “kill-bit” associated to the ActiveX printing control used by Reporting Services 2005.

Hotfix KB956803 only affects Windows XP & Windows 2003 platforms while Windows 2000, Vista and 2008 platforms were not affected.  Hotfix KB956391 seems intended to patch vulnerabilities within the Office products.

 

There are a few ways to go about it and correct it:

 

Possible Solutions on the (Client Side)

1)      Uninstall both hotfixes (KB956803 & KB956391)

2)      Install the following Reporting Services update (http://www.microsoft.com/downloads/details.aspx?FamilyID=82833f27-081d-4b72-83ef-2836360a904d&DisplayLang=en)

3)      Delete a single key in the registry (Which is what I chose)

 

Corrective Steps for item 3

a)      I located and deleted the following key from the registry. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{FA91DF8D-53AB-455D-AB20-F2F023E498D3}]

b)      Then I had restarted (close/re-launched) all IE sessions

c)       Browsed to the Reporting Services url

d)      Opened a report

e)      Clicked the print button (if you have or haven’t installed the print client you may or may not receive the yellow “Install ActiveX” dialog just below the IE header area. You may just receive the Print Dialog instead.)

f)       The report printed fine

g)      I restarted the system and tried it again using a different report and had no further issues. 

Posted via email from wetmatter nonsense