Trigger for insert/delete record and RollBack Operation.

Trigger for backup data from sales table of dbPicnPay to Sales table of dbBackUp database. After Delete record from sales table of dbPicnPay that record will insert into Sales table of dbBackUp database.

create trigger TrigSalesHistory on dbPicnPay.dbo.Sales
for delete
as
begin
insert into dbBackUp.dbo.Sales
select * from deleted
end


Trigger for backup data from sales table of dbPicnPay to SalesNew table of dbBackUp database. After Insert record to sales table of dbPicnPay that record will also insert into SalesNew table of dbBackUp database.

create trigger TrigSalesHistory on dbPicnPay.dbo.sales
for insert
as
begin
insert into dbBackUp.dbo.SalesNew
select * from inserted
end




After Insert/Delete record from Sales table of dbPicnPay that operation make failed:

create trigger SalesHistoryS on dbPicnPay.dbo.sales
for delete,insert
as
begin
rollback
end

How to Rename a Column Name or Table Name in SQL SERVER

Table Name Rename :

Command: SP_RENAME 'TableOldName', 'NewTableName'


Column Name Rename :

Command: SP_RENAME 'TableName.[ColumnOldName]', '[NewColumnName]'


References: http://msdn.microsoft.com/en-us/library/aa238878%28v=sql.80%29.aspx

Add Serial No/Identity Column in Select Statement SQL Script in run time

Table Name : EmployeeInfo
We have to Select EmpName, Address, and Extra Serial column then


select e.EmpName, e.Address,id_col=count(*)
from EmployeeInfo e,EmployeeInfo b
where (e.EmpName+e.Address)<=(b.EmpName+b.Address)
group by e.EmpName, e.Address
order by id_col

or

select EmpName, Address, id_col=IDENTITY(int,1,1)
into #tmpEmp
from EmployeeInfo

select * from #tmpEmp

IIS 7 in Windows server 2008

IIS 7 IP Address change stopped website

For that problem we  have to change IP Address from listen of windows server 2008.

Click Start, click Run, type cmd, and then click OK.

for show listed ip write in command line> netsh http show iplisten

for add ip in list write in command line> netsh http add iplisten xxx.xxx.x.x 


for delete listed ip write in command line> netsh http delete iplisten xxx.xxx.x.x 


Ref: http://support.microsoft.com/kb/954874

Dynamically number rows in a SELECT Transact-SQL statement

Select sno=count(*),a.employee_name
from empmaster a,empmaster b
where a.employee_name >= b.employee_name
group by a.employee_name
order by sno

sno Employee_name
--- -----------------
1 Shidkers
2 Rana
3 Admin
4 AKRAMOL
5 ASAD
6 BABUL
7 FARIDUL ISLAM
8 JAHANGIR
9 JAHID HASAN
10 LITON SHEIKH
11 MAHFUZ



Ref: http://support.microsoft.com/kb/186133

Create a ASP.NET Membership Security Database

Create a ASP.NET Membership Security Database
==========================================

Use System.Security namespace for create/delete/update user, user roles etc. of membership instance we have to create Table, procedure, views. I will explain how to add ASP.NET 2.0/3.5 or later Membership Security tables, stored procedures, views to existing SQL Server database.

suggestion: create a test database first to test this, don’t do directly on production database!

Prerequisites:
Visual Studio 2005/2008 installed
SQL Server 2005/08 installed (with a current database and your windows account with dbo/admin rights)
  1. Locate your SQL Database – make sure you have rights to it
  2. Locate the Visual Studio Command Prompt (All Programs; Microsoft Visual Studio 2005; Visual Studio Tools; Visual Studio 2005 Command Prompt)
run the following Command: aspnet_regsql -S (local) -E -d TestDatabseName -A all

Here, Instead of (local) we can use serverName.


For More details write aspnet_regsql /? on Visual Studio Command prompt.




SQL Script for Correlated Update with Aggregate function / subquery

Sample Query
==============================================================

update R
set R.opn_sal=Q.TSales,r.opn_sal_amt=Q.TSalesAmt
from RDeptStock R,(
SELECT D.prd_id, SUM(D.prd_qty) AS TSales, SUM(D.prd_qty*D.CRate) AS TSalesAmt FROM
sale_detail_cost as D WHERE (D.dept_id = @did)
AND (D.sales_date < @xdate)
GROUP BY D.prd_id) Q
where R.prd_id=Q.prd_id


update s
set s.CRate= (r.Opn_rec_amt-r.Opn_sal_amt+r.Cur_rec_amt)/(r.Opn_rec-r.Opn_sal+r.Cur_rec)
from sale_detail_cost s,RDeptStock r
where r.prd_id=s.prd_id and (s.sales_date >= @xdate) and
(s.sales_date <=@edate) and s.dept_id=@did
and r.Opn_rec-r.Opn_sal+r.Cur_rec<>0


==========================

reference:
http://www.sqlusa.com/bestpractices2005/updatewithcorrelatedsubquery/
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60899
http://www.sql-server-performance.com/forum/threads/aggregate-function-in-update-statement.12043/
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=79960

Connection & Report call via ODBC and Number to Text

Connection:

Public Cnn As ADODB.Connection
Public strCn As String
Public crcon As String

Public Sub cnDb()
Dim strCn As String
Set Cnn = New ADODB.Connection
'strCn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dbUCL;Data Source=DCLSERVER"
'strCn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dbUCL;Data Source=dcl_db"
strCn = "Provider=MSDASQL.1;Persist Security Info=False;password=mm1234;User ID=sa;Data Source=gcl_db;"

'cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Password=sa;User ID=sa;Data Source=NUB_Tool;"

Cnn.Open strCn
End Sub
Public Function FTable(strT As String, rsA As ADODB.Recordset)
'Call cnDb
Set rsA = New ADODB.Recordset
rsA.Open strT, Cnn, adOpenKeyset, adLockOptimistic, adCmdTable
End Function
Sub main()
MDIfrmMain.Show
'frmLogin.Show 1
frmLogin_main.Show 1
End Sub
Public Function FSql(strS As String, rsA As ADODB.Recordset)
'Call cnDb
Set rsA = New ADODB.Recordset
rsA.Open strS, Cnn, adOpenKeyset, adLockOptimistic, adCmdText
End Function






Report:
Dim x As New islip 'IssueSlip


x.Text4.SetText (Sr)
x.Text6.SetText (xd)
x.Text10.SetText (dname)
x.Text12.SetText ("") '(ename)

x.PaperSize = crPaperLetter
x.VerifyOnEveryPrint = True
x.Database.LogOnServer "pdsodbc.dll", "gcl_db", "dbGCL", "sa", "mm1234"

With CRViewer1
.EnableGroupTree = False
.Zoom 100
.Top = 0
.Left = 0
.Height = Me.Height - 1000
.Width = Me.Width - 120
.ReportSource = x
.ViewReport
End With




Number to Text:
Public Function ConvertNumber(strNumber As String) As String

'====Converts a number to word===================

Dim tk As String
Dim paisa As String
Dim ten As String
Dim hund As String
Dim thou As String
Dim lac As String
Dim crore As String
Dim list(100) As String
Dim length As Integer
Dim lencr As Integer
Dim pointl As Integer
Dim croreten As String
Dim crorehund As String
Dim crorethou As String
Dim crorelac As String
Dim crorecr As String
Dim tkword As String


list(0) = ""
list(1) = "One"
list(2) = "Two"
list(3) = "Three"
list(4) = "Four"
list(5) = "Five"
list(6) = "Six"
list(7) = "Seven"
list(8) = "Eight"
list(9) = "Nine"
list(10) = "Ten"
list(11) = "Eleven"
list(12) = "Twelve"
list(13) = "Thirten"
list(14) = "Forteen"
list(15) = "Fifteen"
list(16) = "Sixteen"
list(17) = "Seventen"
list(18) = "Eighteen"
list(19) = "Ninteen"
list(20) = "Twenty"
list(21) = "Twenty One"
list(22) = "Twenty Two"
list(23) = "Twenty Three"
list(24) = "Twenty Four"
list(25) = "Twenty Five"
list(26) = "Twenty Six"
list(27) = "Twenty Seven"
list(28) = "Twenty Eight"
list(29) = "Twenty Nine"
list(30) = "Thirty"
list(31) = "Thirty One"
list(32) = "Thirty Two"
list(33) = "Thirty Three"
list(34) = "Thirty Four"
list(35) = "Thirty Five"
list(36) = "Thirty Six"
list(37) = "Thirty Seven"
list(38) = "Thirty Eight"
list(39) = "Thirty Nine"
list(40) = "Forty"
list(41) = "Forty One"
list(42) = "Forty Two"
list(43) = "Forty Three"
list(44) = "Forty Four"
list(45) = "Forty Five"
list(46) = "Forty Six"
list(47) = "Forty Seven"
list(48) = "Forty Eight"
list(49) = "Forty Nine"
list(50) = "Fifty"
list(51) = "Fifty One"
list(52) = "Fifty Two"
list(53) = "Fifty Three"
list(54) = "Fifty Four"
list(55) = "Fifty Five"
list(56) = "Fifty Six"
list(57) = "Fifty Seven"
list(58) = "Fifty Eight"
list(59) = "Fifty Nine"
list(60) = "Sixty"
list(61) = "Sixty One"
list(62) = "Sixty Two"
list(63) = "Sixty Three"
list(64) = "Sixty Four"
list(65) = "Sixty Five"
list(66) = "Sixty Six"
list(67) = "Sixty Seven"
list(68) = "Sixty Eight"
list(69) = "Sixty Nine"
list(70) = "Seventy"
list(71) = "Seventy One"
list(72) = "Seventy Two"
list(73) = "Seventy Three"
list(74) = "Seventy Four"
list(75) = "Seventy Five"
list(76) = "Seventy Six"
list(77) = "Seventy Seven"
list(78) = "Seventy Eight"
list(79) = "Seventy Nine"
list(80) = "Eighty"
list(81) = "Eighty One"
list(82) = "Eighty Two"
list(83) = "Eighty Three"
list(84) = "Eighty Four"
list(85) = "Eighty Five"
list(86) = "Eighty Six"
list(87) = "Eighty Seven"
list(88) = "Eighty Eight"
list(89) = "Eighty Nine"
list(90) = "Ninty"
list(91) = "Ninty One"
list(92) = "Ninty Two"
list(93) = "Ninty Three"
list(94) = "Ninty Four"
list(95) = "Ninty Five"
list(96) = "Ninty Six"
list(97) = "Ninty Seven"
list(98) = "Ninty Eight"
list(99) = "Ninty Nine"

tkword = ""
crore = ""
lac = ""
thou = ""
hund = ""
ten = ""
crorecr = ""
crorelac = ""
crorethou = ""
crorehund = ""
croreten = ""
ConvertNumber = ""
lencr = 0

pointl = InStr(1, strNumber, ".", vbTextCompare)


If pointl > 0 Then
tk = VBA.Mid(strNumber, 1, pointl - 1)
paisa = VBA.Mid(strNumber, pointl + 1, Len(strNumber))
Else
tk = CStr(Val(strNumber))
End If
length = Len(tk)

While length > 0
Select Case length
Case Is > 7: crore = VBA.Mid(tk, 1, length - 7)
tk = VBA.Mid(tk, length - 6, length)

Case Is > 5: lac = VBA.Mid(tk, 1, length - 5)
tk = VBA.Mid(tk, length - 4, length)

Case Is > 3: thou = VBA.Mid(tk, 1, length - 3)
tk = VBA.Mid(tk, length - 2, length)

Case Is > 2: hund = VBA.Mid(tk, 1, length - 2)
tk = VBA.Mid(tk, length - 1, length)

Case Is > 0: ten = tk
tk = ""

End Select
length = Len(tk)
Wend

If Val(crore) <> 0 And Val(crore) < 1000000000 Then

lencr = Len(crore)
length = Len(crore)
While length > 0
Select Case length
Case Is > 7: crorecr = VBA.Mid(crore, 1, length - 7)
crore = VBA.Mid(crore, length - 6, length)

Case Is > 5: crorelac = VBA.Mid(crore, 1, length - 5)
crore = VBA.Mid(crore, length - 4, length)

Case Is > 3: crorethou = VBA.Mid(crore, 1, length - 3)
crore = VBA.Mid(crore, length - 2, length)

Case Is > 2: crorehund = VBA.Mid(crore, 1, length - 2)
crore = VBA.Mid(crore, length - 1, length)

Case Is > 0: croreten = crore
crore = ""

End Select
length = Len(crore)
Wend

End If


If Val(crorecr) <> 0 Then
tkword = tkword + list(Val(crorecr)) + " Crore "
End If
If Val(crorelac) <> 0 Then
tkword = tkword + list(Val(crorelac)) + " Lac "
End If
If Val(crorethou) <> 0 Then
tkword = tkword + list(Val(crorethou)) + " Thousand "
End If

If Val(crorehund) <> 0 Then
tkword = tkword + list(Val(crorehund)) + " Hundred "
End If
If Val(croreten) <> 0 Then
tkword = tkword + list(Val(croreten)) + " Crore "
End If
If Val(croreten) = 0 And lencr > 0 Then
tkword = tkword + " Crore "
End If


If Val(lac) <> 0 Then
tkword = tkword + list(Val(lac)) + " Lac "
End If
If Val(thou) <> 0 Then
tkword = tkword + list(Val(thou)) + " Thousand "

End If
If Val(hund) <> 0 Then
tkword = tkword + list(Val(hund)) + " Hundred "

End If
If Val(ten) <> 0 Then
tkword = tkword + list(Val(ten))

End If
ConvertNumber = tkword + " Taka "

If Val(paisa) <> 0 Then
ConvertNumber = ConvertNumber + " And " + list(Val(paisa)) + " Paisa "
End If

End Function

How to Find List of Tables Name and Columns or Fields Name of Specific Table in SQL Server

To Find the name of the tables name need to write this script:


SELECT name
FROM dbo.sysobjects
WHERE xtype = 'U'

To Select Names of the Fields or Columns of Specific Table by Name(SQL Script):

SELECT [name] AS [Column name]
FROM syscolumns
WHERE id = (SELECT id
FROM sysobjects
WHERE type = 'U'
AND [NAME] = 'Table_Name')

How to run IIS for ASP.NET in windows server 2003

Step 1:
setup iis then allow all web service extention

Step 2: Copy the published project (that worked previously) to the wwwroot

Step 3: right click on my computer->manage
then expanded and right click on Internet Information Service->website->default web site go to Propertise window
go to Document tab->remove all page then add only one page thats run as Home page

apply-> ok

Now also shows this error message:

unrecognized attribute 'type' error solve:


Step 4:


IIS framework 2.0.5......... install by command........
in run just type the below code:
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i


hope this article will help every one