Wednesday 28 December 2011

Common Table Expressions

Microsoft offers the following four advantages of CTEs:

  • Create a recursive query.

  • Substitute for a view when the general use of a view is not required; that is, you do not have to store the definition in metadata.

  • Enable grouping by a column that is derived from a scalar sub select, or a function that is either not deterministic or has external access.

  • Reference the resulting table multiple times in the same statement.

Using a CTE offers the advantages of improved readability and ease in maintenance of complex queries. The query can be divided into separate, simple, logical building blocks. These simple blocks can then be used to build more complex, interim CTEs until the final result set is generated. 


  • About are as follow


A common table expression (CTE) can be thought of as a temporary result set that is defined 

Friday 23 December 2011

Difference Between STUFF Vs REPLACE

STUFF - Delete a specified length of characters and insert
another set of characters at a specified starting point.


ex: SELECT STUFF('abcdefghi', 3, 3, 'ABC')
Go
Answer is: abABCfghi

REPLACE - Replace all occurrences of the second given string
expression in the first string expression with a third
expression.
For Example: SELECT REPLACE('Abhay', 'a', 'v')
Answer is: vbhavy

Monday 14 November 2011

How to enable/disable compile errors warning in Visual Studio

  1. From the "Tools" menu, select "Options".
  2. In the dialog that appears, expand "Projects and Solutions", and click "Build and Run".
  3. On the right side, you'll see a combo box labeled "On Run, when build or deployment errors occur".
    • If you want to disable the message box, select either "Do not launch" or "Launch old version" (which will launch the old version automatically).
    • If you want to enable the message box, select "Prompt to launch" which will ask you each time.
   VS "Build and Run" Options
Of course, as people have suggested in the comments, this means that your code has errors in it somewhere that are preventing it from compiling. You need to use the "Error List" to figure out what those errors are, and then fix them.

Thursday 25 August 2011

Pass Dynamic Connection String to SSRS Reports

SSRS 2005 ReportViewer is 'Shrinking' my Reports

I've found the solution to SSRS shrinking my reports. For reference, you have to do three things
  1. Delete the declaration from my hosting aspx page
  2. Set the Report Viewer's AsyncRendering property to false.
  3. Set the Report Viewer's Width property to 100%
Apparently there is a bug in SSRS 2005 with its XHTML rendering engine which is now fixed with the engine rebuild in SSRS 2008.

Tuesday 9 August 2011

RegisterStartupScript vs RegisterClientScriptBlock


I have a site with loads of pages with Ajax tabbed containers on them. Generally each tabbed container is contained within an Update Panel. Some have additional Update Panels on the tabs.

Whenever a user clicks an Update button, I go back to the server, check if they have permission to do the action they are doing and, if they don't return to the page and EITHER do this:



I find, on various pages, one works and the other does not. If I'm using RegisterClientScriptBlock and the alert does not show, I change it to RegisterStartupScript - and it works - the alert shows.

But the reverse can also be true. Sometimes RegisterStartupScript does not work, and if I change it to RegisterClientScriptBlock it works.

I have checked this out in detail on different pages - where the code is pretty much identical i.e. there is an Update Panel containing a tabbed container and nothing else. Sometimes I have to use RegisterStartupScript - sometimes I have to use RegisterClientScriptBlock.

RegisterClientScriptBlock -> Put a function or a block of code (javascript) on the page which you may not want executed immediately.

RegisterStartupScript -> Put some code on the page which you want executed as soon as the page finishes loading.


Saturday 16 July 2011

Repeat Tablix Row Header on each page (SSRS 2008)

 Sql Server Reporting Service :

Getting SSRS 2008 to repeat the Tablix header is not a straight forward setting and requires some additional steps to do so. This used to be very simple thing till SSRS 2005, there basically we just used to right click on the Table, select the check box “Repeat header rows on each page” and we are done. 




We need to take some additional steps to make this working in SSRS 2008 and the primary reason is the Table structure has been changed in SSRS 2008. Now we have “Tablix” in place of “Table” which is the combination of Table and Matrix.

Here are the steps needed to make sure Tablix Row header is shown is each page.
1. Even though the Tablix has Row/Column header properties in the property pane but this does not work especially when the row grouping is used in Tablix.








2. In order to make sure that the Tablix row header is repeated in each page, we need to go the Advance Mode settings of Tablix.
In the bottom of Report Designer-->Under Groupng Pane-->Column Group-->Click on Advance Mode




3. In the Row Groups pane, click the static member of the row you need to repeat.
4. When we select the Static Member, the corresponding cell in the Tablix will be selected. If this confirms the cell which needs to be repeated, go to the properties of this Static Member.
5. Set the KeepWithGroup property
a) For a Static row that is above a group, select “After
b) For a Static row that is below the group, select “Before” if the Static Row is below the Group.
6. The last thing would be to set the RepeatOnNewPage property “True





For more details please see the below msdn article.

http://msdn.microsoft.com/en-us/library/cc627566.aspx