Wednesday, December 18, 2013

Sql Server Query Techniques


Select Table using Column name
-----------------------------------------------------------------------------
SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%Column%'

 Select Procedures using name
-----------------------------------------------------------------------------
SELECT DISTINCT
    o.name AS Object_Name,o.type_desc
    FROM sys.sql_modules        m 
        INNER JOIN sys.objects  o ON m.object_id=o.object_id
    WHERE m.definition Like '%SP_Name%'

Query Your Database for a List of Triggers
-----------------------------------------------------------------------------
IF OBJECT_ID('sys.schemas') IS NULL 
    SELECT B.name + '.' + A.name
      FROM sysobjects A, sysusers B
     WHERE A.type = 'TR'
       AND B.uid = OBJECTPROPERTY ( A.id , 'ownerid' ) 
     ORDER BY A.name
ELSE
    SELECT B.name + '.' + A.name
      FROM sysobjects A, sys.schemas B
     WHERE A.type = 'TR'
       AND B.schema_id = A.uid 
     ORDER BY B.name + '.' + A.name

Query Your Database for a List of View 
-----------------------------------------------------------------------------
SELECT  * 
FROM   INFORMATION_SCHEMA.VIEWS 
WHERE  VIEW_DEFINITION like '%table%'




Monday, October 21, 2013

SQL SERVER – Query to Find First and Last Day of Current Month

 Following query will run respective to today’s date. It will return Last Day of Previous Month, First Day of Current Month, Today, Last Day of Previous Month and First Day of Next Month respective to current month.



DECLARE @mydate DATETIME
SELECT @mydate GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,'Last Day of Previous Month'UNION
SELECT 
CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101AS Date_Value,'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101AS Date_Value'Today' ASDate_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,'First Day of Next Month'
GO

Friday, October 11, 2013

Get debug console log in iOS

- (NSString *)getConsoleLogFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return nil;
}
return [documentsDirectory stringByAppendingPathComponent:fileName];
}


NSString *fileName = @"xx.log";
NSString *logFilePath = [self getConsoleLogFilePath];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);




Tuesday, September 10, 2013

Print "Hello World" Without Using Semicolon


Source Code :
 #include <stdio.h>  
 int main() {  
 if(printf("Hello World")) {  
 /*  
 * It prints Hello world and returns the  
 * value 11 i.e Length of the String  
 */  
 }  
 }  



Monday, June 10, 2013

Execute HTTP GET in Android

Sample Code :

try {
       HttpClient client = new DefaultHttpClient();
       String targetUrl = "http://www.example.com";
       HttpGet httpGet = new HttpGet(targetUrl);
       HttpResponse response = null;       
       response = client.execute(httpGet);
       HttpEntity entity = response.getEntity();
       if(entity!=null){
             Log.v("GET RESPONSE", EntityUtils.toString(entity));
       }
}
catch(Exception e){
       e.printStackTrace();
}

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...