Monday, September 27, 2010

[.NET] Installation Notes

When installing any .NET Framework if an error occurred then try to turn off the ISS then redo the installation.

Friday, September 24, 2010

[MSSQL] List out all database information

This will display all database information

select * from sys.databases

Wednesday, September 22, 2010

[MSSQL] Cursor and While multiple loop sample

Below sample usage of Cursor and While with multiple loop

--fixing missing document reviewer
declare @site_no varchar(10), @siteno varchar(10), @docid as bigint, @sitever as int
DECLARE c1 CURSOR read_only
FOR
select siteno from podetails where pono='HOT 10020567'
OPEN c1
FETCH NEXT FROM c1
INTO @site_no
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT convert(varchar(max),@site_no)
--second loop
update wftransaction set rstatus=2 where site_id in (select site_id from codsite where site_no=@site_no)
DECLARE c2 CURSOR read_only
FOR
select (select site_no from codsite where site_id=wft.site_id) siteno, docid, siteversion from wftransaction wft
where site_id in (select site_id from codsite where site_no=@site_no) and tsk_id=5 and enddatetime is null
OPEN c2
FETCH NEXT FROM c2
INTO @siteno,@docid,@sitever
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT convert(varchar(max),@siteno)+' '+convert(varchar(max),@docid)+' '+convert(varchar(max),@sitever)
exec refreshingWFReview @siteno,@docid,@sitever
FETCH NEXT FROM c2
INTO @siteno,@docid,@sitever
END
CLOSE c2
DEALLOCATE c2
--end secod loop
FETCH NEXT FROM c1
INTO @site_no
END
CLOSE c1
DEALLOCATE c1

[MSSQL] Cursor and While loop sample

Below sample usage of Cursor and While loop

--fixing missing document reviewer
declare @siteno varchar(10), @docid as bigint, @sitever as int
DECLARE c1 CURSOR READ_ONLY
FOR
select (select site_no from codsite where site_id=wft.site_id) siteno, docid, siteversion from wftransaction wft
where site_id in (select site_id from codsite where site_no='SKY078D') and tsk_id=5 and enddatetime is null
OPEN c1
FETCH NEXT FROM c1
INTO @siteno,@docid,@sitever
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT convert(varchar(max),@siteno)+' '+convert(varchar(max),@docid)+' '+convert(varchar(max),@sitever)
exec refreshingWFReview @siteno,@docid,@sitever
FETCH NEXT FROM c1
INTO @siteno,@docid,@sitever
END
CLOSE c1
DEALLOCATE c1

Tuesday, September 7, 2010

[MSSQL] Temporary Table Implementation

Following implementation of temporary tables which can be used to replace stored procedure.

--checking if exist
IF OBJECT_ID('tempdb..#temp') IS NULL
begin
CREATE TABLE #tempTable1 (
field1 datetime NOT NULL
)
end

--adding data
insert into #tempTable1
select top 1 date from anytable

--do what ever here
select * from #tempTable1

--finaly destroy it
DROP TABLE tempdb..#tempTable1