Blog Archives

Create SQL script for Tables in Database

select ‘create table [‘ + so.name + ‘] (‘ + o.list + ‘)’ + CASE WHEN tc.Constraint_Name IS NULL THEN ” ELSE ‘ALTER TABLE ‘ + so.Name + ‘ ADD CONSTRAINT ‘ + tc.Constraint_Name + ‘ PRIMARY KEY ‘ +

Tagged with: ,
Posted in SQL Server

Select one row from detail records based on condition.

I often come across the issue to return one row from detail table like invoice items or order details for one customer for specific condition. i.e. show me the max order product for each customer and order that kind of

Tagged with: ,
Posted in SQL Server

SQL SERVER TRY..CATCH

In SQL Server 2000, Exception was handle by the @@error variable where after each statement SQL Server sets @@error to “0” if the statement was successful, and if not then it will filled by the error number. you can also

Tagged with: ,
Posted in SQL Server