Thursday, October 22, 2015

SQL Table Row Data show in column data




 SELECT *  
 FROM (SELECT CAST(mlblmsg AS varchar(max)) AS mlblmsg,clblcode FROM warninglabels) t  
 PIVOT (MAX(mlblmsg)  
 FOR clblcode IN ([0001],[0002],[003],[0004],[0005],[0006]))p  



How to find if a Column is used anywhere in the database

To get the table where this column use you can use this query.

 SELECT *  
 FROM sys.tables  
 WHERE tables.object_id IN (SELECT  
      OBJECT_ID  
 FROM sys.columns  
 WHERE columns.name LIKE '%CDRUGNAME%') -- use your column name  


SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...