Tuesday 10 May 2011

SQL Search for a String in all Tables

Declare @TN as varchar(200), @CN as varchar(200), @myValue varchar(30), @SQL as nvarchar(1000) 
, @SN as varchar(200), @Exact_Match bit 
  
Create Table #myTable (Table_Name varchar(200), Column_Name varchar(200), Number_Of_Rows int) 
  
-- Replace @myValue with the value you're searching for in the database 
Set @myValue = 'mySearchValue'  
-- 0 for LIKE match, 1 for exact match 
Set @Exact_Match = 0     
  
Declare myCursor Cursor For 
Select T.Table_Name, C.Column_Name, T.Table_Schema 
From INFORMATION_SCHEMA.TABLES T Inner Join INFORMATION_SCHEMA.COLUMNS C  
On T.Table_Schema = C.Table_Schema And T.Table_Name = C.Table_Name 
Where T.Table_Name Not In ('dtproperties') And Table_Type = 'Base Table' 
And C.Data_Type In ('varchar','char','nvarchar','nchar','sql_variant') 
--And C.Data_Type In ('text','ntext') 
--And C.Data_Type In ('tinyint','int','bigint','numeric','decimal','money','float','smallint','real','smallmoney') 
--And C.Data_Type In ('datetime','dmalldatetime') 
-- Fields not searched: image, uniqueidentifier, bit, varbinary, binary, timestamp 
Open myCursor 
Fetch Next From myCursor Into @TN, @CN, @SN 
While @@Fetch_Status <> -1 
Begin 
        If @Exact_Match = 0 
                Set @SQL = N'Insert Into #myTable Select ''' + @SN + '.' + @TN + ''', ''' + @CN + ''', Count(*) From [' + @SN + '].[' + @TN + '] Where [' + @CN + '] Like ''%' + @myValue + '%''' 
            Else 
                Set @SQL = N'Insert Into #myTable Select ''' + @SN + '.' + @TN + ''', ''' + @CN + ''', Count(*) From [' + @SN + '].[' + @TN + '] Where [' + @CN + '] = ''' + @myValue + '''' 
        --Print @SQL 
        Exec sp_executesql @SQL  
        Fetch Next From myCursor Into @TN, @CN, @SN 
End 
Close myCursor 
Deallocate myCursor 
Select * From #myTable Where Number_Of_Rows > 0 Order By Table_Name 
Drop Table #myTable

Thursday 5 May 2011

SSRS 2008 Report String Filter with LIKE operator

goto the Filters in Tablix or Group,
Add the filter,
select Expression as your Fieldname to be filtered on,
select operator LIKE
in value when you click fx button it will show you options in new window
click parameters and select the parameter you created in the report.
you'll see =Parameters!ParameterName.Value
change that to = "*" & Parameters!ParameterName.Value & "*"

SSRS 2008 Paging shows Question mark (?)

Yes I got confused as well as to what this suddenly a new thing in SSRS 2008 and how to solve it, I even thought its a bug, but guess what, its a feature Microsoft has introduced question mark is there because report did not render all the pages and only current page worth of records were processed, it is called On Demand Report Processing.



Yes I do understand the potential of massive performance gains but lets be honest whats the point of showing Page 1 of 2? its not really helpful.

Here we go, you will have to add a little piece of code in your report, so add a textbox in your header or footer containing =Globals!TotalPages, please note that its only allowed in the header or footer, and then you'll see that report will show current number of pages.




 

Tuesday 3 May 2011

Appraisal vs Resignation

A newly joined trainee asks his boss "what is the meaning of appraisal?"
Boss: "Do you know the meaning of resignation?"
Trainee: "Yes I do"

Boss: "So let me make you understand what a appraisal is by comparing it with resignation"

Comparison study: Appraisal and Resignation Appraisal

In appraisal meeting they will speak only about your weakness, errors and failures.
In resignation meeting they will speak only about your strengths, past achievements and success.

In appraisal you may need to cry and beg for even 10% hike.
In resignation you can easily demand (or get even without asking) more than 50-60% hike.

During appraisal, they will deny promotion saying you didn't meet the expectation, you don't have leadership qualities, and you had several drawbacks in our objective/goal.
During resignation, they will say you are the core member of team; you are the vision of the company how can you go, you have to take the project in shoulder and lead your juniors to success.

There is 90% chance for not getting any significant incentives after appraisal.
There is 90% chance of getting immediate hike after you put the resignation.

Trainee: "Yes boss enough, now I understood my future. For an appraisal I will have to resign..!!