July 2010
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
262728293031  

Sql Server Tip 3

Tip#3: Try to use CAST instead of CONVERT. CAST is ANSI-92 standard but CONVERT works in MS SQL server only. Also, some CONVERT styles may be deprecated in future MS SQL releases.

How to reset Identity Increment value in MS SQL

Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, which we saw in the last section. But what if we wish to simply get rid of the data but not the table itself? For this, we can use the TRUNCATE TABLE command. [...]

Configuring Microsoft SQL Express 2005

Microsoft SQL Express 2005 provides enterprise class database performance for free. However it does have some limitations when compared to the full version of SQL Server. But these limitations are not likely to adversely affect most PaperCut NG users. These limitations include

4GB limit on database sizes
Limited to only use 1 CPU
Limited to only use 1GB [...]

SQL SERVER TIP

http://www.sql-server-performance.com/

store procedure call store procedure

<script type=”text/javascript”><!–
google_ad_client = “pub-2910472071369479″;
//728×90, created 11/20/07
google_ad_slot = “7313632958″;
google_ad_width = 728;
google_ad_height = 90;
//–></script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js“>
</script>

src=”http://pagead2.googlesyndication.com/pagead/show_ads.js” mce_src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>

set nocount on
declare @sql nvarchar(2000)
declare @comp_code nvarchar(255), @pin nvarchar(255), @LoanType nvarchar(255), @datefrom nvarchar(255)
declare @temp_id int, @n int
declare @docNo nvarchar(20)

create table #temp
(
 _id int IDENTITY,
 Company nvarchar(255),
 PIN nvarchar(255),
 LoanType nvarchar(255),
 df nvarchar(255)
)

insert into #temp
select Company, PIN, LoanType, convert(varchar,convert(datetime, DateFrom, 103),112) as df
from sheet1 where LoanType in (’01′,’02′,’03′,’04′,’05′) [...]

store procedure for return value string format

CREATE PROCEDURE get_running_number
@id int,
@docNO varchar(20)  out
AS
begin
 declare @_id nvarchar(20)
 declare @i int
 set @_id = cast(@id as nvarchar)
 set @i = len(@_id)
 while (@i<5)
 begin
  set @_id = ‘0′ + @_id
  set @i = @i +1
 end
 set @_id = ‘WF0711′ + @_id
      select @docNO =  @_id
end
GO

sql datetime format

select
Company, PIN, Type, convert(varchar,convert(datetime, DateFrom, 103),112) as df
from sheet1
where Type in (’01′,’02′,’03′,’04′,’05′)

MSSQL 2000 Log file full

- backup log DATABSENAME with no_log

- shink  thik true on top checkbox and set value = 20%

Paging with Store procedure

set nocount on

declare @FirstRec int, @LastRec int
declare @Page int, @RecsPerPage int
set @Page = 4
set @RecsPerPage = 3

CREATE TABLE #TempTable1
(
 ID int IDENTITY,
 Comp_Code varchar(3),
 Org_id varchar(8)
)

INSERT INTO #TempTable1 (Comp_Code, Org_id)
SELECT Comp_Code, Org_id FROM WF_MST_VENDOR

SELECT @FirstRec = (@Page – 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

SELECT *,MoreRecords = ( SELECT COUNT(*)  FROM #TempTable1 TI  WHERE TI.ID [...]

DataSet Paging with Store procedure

CREATE PROCEDURE sp_PagedItems
 (
  @Page int,
  @RecsPerPage int
 )
AS
– We don’t want to return the # of rows inserted
– into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON

–Create a temporary table
CREATE TABLE #TempItems
(
 ID int IDENTITY,
 Name varchar(50),
 Price currency
)

– Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Name, Price)
SELECT Name,Price FROM tblItem ORDER BY Price
– [...]