Stored Procedures For Inserting And Deleting Data
May 2, 2007Hi, am new to sql server. Please some one send me some introduction abt stored procedures and some coding exammples to update and fetch the data from datasourece.
thanks.
Hi, am new to sql server. Please some one send me some introduction abt stored procedures and some coding exammples to update and fetch the data from datasourece.
thanks.
I am trying to write a stored procedure to delete something from a table but I keep getting sytax error.
This is the code I am using:
DELETE [tablename].[tablerow], [tablename].[tablerow]
FROM [tablename]
WHERE (((tablename.tablerow)="void"));
This works as an Access query but not as a stored procedure.
Hi All!
I know this must be a very silly question but, what is the PLSQL string I have to use to delete a stored procedure in a database? Essentially I have to remove a stored procedure that comes from a database backup every night because it belongs to a user and that user has to be recreated in the new SQL Server 2000. Simply put:
1. Production database comes into test database
2. Remove copy of stored procedure since it can not be set to dbo user because there is another copy with the same name that belongs to dbo.
3. Remove user
4. Add user (this one brings login name since the restored one didn't)
5. Have a nice day
I've got everything except removing the stored procedure so I will really appreciate the help.
Thank you all!
How to insert if-else statements to my stored procedure if i am only going to set a condition on a single column of the table?
Ex. SELECT a.m0020_pat_id, a.M0040_PAT_LNAME + ', ' + a.M0040_PAT_FNAME + ' ' + a.M0040_PAT_MI as patientName,
a.M0030_START_CARE_DT as socdate, M0906_DC_TRAN_DTH_DT as transferdate,M0906_DC_TRAN_DTH_DT+14 as DueDate, M0230_PRIMARY_DIAG_ICD, c.[description] AS M0230_PRIMARY_DIAG_DESC,
d.name facilityName, e.FacilityTypeName,a.EffectiveDate_End
( i will specify that if MO906_DC_TRAN_DTH+14 is greater than EffectiveDate_End THEN MO906_DC_TRAN_DTH+14=EffectiveDate_end)
shemay
Hello there!
I've been sitting here thinking how to work through this problem but I am stuck. First off I have two tables I am working with.
Request TablerqstKey (this is the primary key and has the identity set to yes)entryDte datetimesummary nvarchar(50)etryUserID nvarchar(50)rqstStatusCdeKey bigint
ReqStatusCode TablerqstStatusCdeKey bigintstatusCode nvarchar(50)
I have webforms that are using Session variables to store information from the webpages into those variables and insert them into these tables. However, I am wanting to insert the rqstStatusCdeKey (from the ReqStatusCode Table) value into the Request Table. The rqstStatusCdeKey value i am wanting to insert is '3' which stands for "in Design" (((this is going to be the default value))). I need help :-/ If you need me to explain more/ clarify, and show more information I can. Thank you so much!!!
Hello,
I'm building an ecommerce website which requires customers to create an account before they go ahead with a purchase. I have a createaccount.aspx page in Visual Web Developer 2005 with text boxes where users can enter their details (email, password, name and address). I'm trying to insert the information which users type into the text boxes into an SQL database table called Customers.
I've dragged and dropped an SQL data source onto my page and have set it to operate on my AddCustomer stored procedure. I've confirgured my data source such that the parameter for each field in the database is set to the appropriate control on the webpage (for example the Email parameter source is "textboxEmail").
I've also placed a button onto my page so that the button click event can act as the trigger for sending the information in the text boxes to the database. I wasn't totally sure how to write code for the button click event such that when the button is clicked, the INSERT stored procedure runs. At the moment I'm using:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
SqlDataSource1.Insert()
End Sub
When I try to run my application I'm getting an error which reads:
Cannot insert the value NULL into column 'Email', table 'C:DOCUMENTS AND SETTINGSLUKE JACKSONMY DOCUMENTSVISUAL STUDIO 2005WEBSITESJACKSONSNURSERIESAPP_DATADATABASE.MDF.dbo.Customers'; column does not allow nulls. INSERT fails.The statement has been terminated.
The error message implies that I haven't set the necessary parameters correctly but I really don't know where I'm going wrong!
The code I'm using for my stored procedure is as follows:
ALTER PROCEDURE AddCustomer
(
@CustomerID int,
@Email nvarchar(50),
@Password nvarchar(MAX),
@Name nvarchar(50),
@Address1 nvarchar(50),
@Address2 nvarchar(50),
@Address3 nvarchar(50),
@City nvarchar(50),
@County nvarchar(50),
@PostCode nvarchar(50)
)
AS
INSERT INTO Customers
(Email, Password, Name, Address1, Address2, Address3, City, County, PostCode)
VALUES
(@Email, @Password, @Name, @Address1, @Address2, @Address3, @City, @County, @PostCode)
I'd be really grateful if anyone could help me out with this.
Thanks in advance,
Luke
p.s. just incase it helps, here's my createaccount.aspx page:
<%@ Page Language="VB" MasterPageFile="~/Master.master" AutoEventWireup="false" CodeFile="createaccount.aspx.vb" Inherits="createaccount" title="Untitled Page" %>
<%-- Add content controls here --%>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<span style="text-decoration: underline"><strong>Create Account<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="AddCustomer" SelectCommandType="StoredProcedure" InsertCommand="INSERT INTO Customers 	(Email, Password, Name, Address1, Address2, Address3, City, County, PostCode) 	VALUES 	(@Email, @Password, @Name, @Address1, @Address2, @Address3, @City, @County, @PostCode)">
<SelectParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:ControlParameter ControlID="textboxEmail" Name="Email" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="textboxPassword" Name="Password" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="textboxName" Name="Name" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="textboxAddress" Name="Address1" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="textboxAddress2" Name="Address2" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="textboxAddress3" Name="Address3" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="textboxCity" Name="City" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="textboxCounty" Name="County" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="textboxPostCode" Name="PostCode" PropertyName="Text"
Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address1" Type="String" />
<asp:Parameter Name="Address2" Type="String" />
<asp:Parameter Name="Address3" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="County" Type="String" />
<asp:Parameter Name="PostCode" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
</strong></span>
<table style="font-weight: bold; width: 394px; text-decoration: underline">
<tr>
<td style="width: 111px; height: 21px; text-align: left">
Email:</td>
<td style="height: 21px">
<asp:TextBox ID="textboxEmail" runat="server" Width="147px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; height: 21px; text-align: left">
Password:</td>
<td style="height: 21px">
<asp:TextBox ID="textboxPassword" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; height: 21px; text-align: left">
Name:</td>
<td style="height: 21px">
<asp:TextBox ID="textboxName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; text-align: left">
Address 1:</td>
<td>
<asp:TextBox ID="textboxAddress" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; height: 21px; text-align: left">
Address 2:</td>
<td style="height: 21px">
<asp:TextBox ID="textboxAddress2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; text-align: left">
Address 3:</td>
<td>
<asp:TextBox ID="textboxAddress3" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; text-align: left">
City:</td>
<td>
<asp:TextBox ID="textboxCity" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; height: 21px; text-align: left">
County:</td>
<td style="height: 21px">
<asp:TextBox ID="textboxCounty" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 111px; text-align: left">
Post Code:</td>
<td>
<asp:TextBox ID="textboxPostCode" runat="server"></asp:TextBox></td>
</tr>
</table>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</asp:Content>
Thanks again
I am trying to insert each record coming from my DataTable object to sql server database. The problem that I have is that I have my stored procedures within the loop and it work only for one record, because it complaing that there are too many parameters. Is there a way i can add up my parameters before the loop and avoid this issue?
Here is the code I am using:Public Sub WriteToDB(ByVal strDBConnection As String, ByVal strFileName As String, ByVal strTable As String)
'Fill in DataTable from AccessDim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName)
Dim adapter As New OleDbDataAdapter()Dim command As New OleDbCommand
Dim DataTable As New DataTableDim sqlCommand = "SELECT * FROM " & strTableDim objDataTable As New DataTable
objConn.Open()
command.CommandType = CommandType.Text
command.Connection = objConn
command.CommandText = sqlCommandadapter = New OleDbDataAdapter(command)DataTable = New DataTable("NFS")
adapter.Fill(DataTable)
'Sql DB vars
'Dim dtToDBComm = "INSERT INTO NFS_Raw(Time, Exch, Status) VALUES ('test', 'test', 'test')"Dim sqlServerConn As New SqlConnection(strDBConnection)Dim sqlServerCommand As New SqlCommand
sqlServerCommand = New SqlCommand("InsertFromAccess", sqlServerConn)
sqlServerCommand.CommandType = CommandType.StoredProcedure
sqlServerConn.Open()For Each dr As DataRow In DataTable.Rows
sqlServerCommand.Parameters.Add(New SqlParameter("@Time", dr.ItemArray(0).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Exch", dr.ItemArray(1).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Status", dr.ItemArray(2).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Msg", dr.ItemArray(3).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Action", dr.ItemArray(4).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@BS", dr.ItemArray(5).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@OC", dr.ItemArray(6).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@CP", dr.ItemArray(7).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Qty", dr.ItemArray(8).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Product", dr.ItemArray(9).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@MMMYY", dr.ItemArray(10).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Strike", dr.ItemArray(11).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Limit", dr.ItemArray(12).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@StopPrc", dr.ItemArray(13).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Type", dr.ItemArray(14).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Rstr", dr.ItemArray(15).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@TIF", dr.ItemArray(16).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@RstrQty", dr.ItemArray(17).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExecQty", dr.ItemArray(18).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@WorkQty", dr.ItemArray(19).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@CxlQty", dr.ItemArray(20).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@AccountNum", dr.ItemArray(21).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchMbrID", dr.ItemArray(22).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@ExchGrpID", dr.ItemArray(23).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchTrdID", dr.ItemArray(24).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@MemberID", dr.ItemArray(25).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@GroupID", dr.ItemArray(26).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@NTrdID", dr.ItemArray(27).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Acct", dr.ItemArray(28).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@ExchTime", dr.ItemArray(29).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchDate", dr.ItemArray(30).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TimeSent", dr.ItemArray(31).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@TimeProcessed", dr.ItemArray(32).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@PA", dr.ItemArray(33).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@OrderNo", dr.ItemArray(34).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TTOrderKey", dr.ItemArray(35).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@IP", dr.ItemArray(36).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@FFT3", dr.ItemArray(37).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@FFT2", dr.ItemArray(38).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@SubmitTime", dr.ItemArray(39).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@SubmitDate", dr.ItemArray(40).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TransID", dr.ItemArray(41).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@SessionID", dr.ItemArray(42).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@SeriesKey", dr.ItemArray(43).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchangeOrderID", dr.ItemArray(44).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Destination", dr.ItemArray(45).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@FlowDeliveryUnit", (dr.ItemArray(46))))sqlServerCommand.Parameters.Add(New SqlParameter("@TimeReceived", dr.ItemArray(47).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@CallbackReceived", dr.ItemArray(48).ToString()))
sqlServerCommand.ExecuteNonQuery()Next
sqlServerConn.Close()
objConn.Close()
End Sub
Thanks for eveones input in advance.
I am trying to insert each record coming from my DataTable object to sql server database. The problem that I have is that I have my stored procedures within the loop and it work only for one record, because it complaing that there are too many parameters. Is there a way i can add up my parameters before the loop and avoid this issue?
Here is the code I am using:Public Sub WriteToDB(ByVal strDBConnection As String, ByVal strFileName As String, ByVal strTable As String)
'Fill in DataTable from AccessDim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName)
Dim adapter As New OleDbDataAdapter()Dim command As New OleDbCommand
Dim DataTable As New DataTableDim sqlCommand = "SELECT * FROM " & strTableDim objDataTable As New DataTable
objConn.Open()
command.CommandType = CommandType.Text
command.Connection = objConn
command.CommandText = sqlCommandadapter = New OleDbDataAdapter(command)DataTable = New DataTable("NFS")
adapter.Fill(DataTable)
'Sql DB vars
'Dim dtToDBComm = "INSERT INTO NFS_Raw(Time, Exch, Status) VALUES ('test', 'test', 'test')"Dim sqlServerConn As New SqlConnection(strDBConnection)Dim sqlServerCommand As New SqlCommand
sqlServerCommand = New SqlCommand("InsertFromAccess", sqlServerConn)
sqlServerCommand.CommandType = CommandType.StoredProcedure
sqlServerConn.Open()For Each dr As DataRow In DataTable.Rows
sqlServerCommand.Parameters.Add(New SqlParameter("@Time", dr.ItemArray(0).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Exch", dr.ItemArray(1).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Status", dr.ItemArray(2).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Msg", dr.ItemArray(3).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Action", dr.ItemArray(4).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@BS", dr.ItemArray(5).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@OC", dr.ItemArray(6).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@CP", dr.ItemArray(7).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Qty", dr.ItemArray(8).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Product", dr.ItemArray(9).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@MMMYY", dr.ItemArray(10).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Strike", dr.ItemArray(11).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Limit", dr.ItemArray(12).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@StopPrc", dr.ItemArray(13).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Type", dr.ItemArray(14).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Rstr", dr.ItemArray(15).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@TIF", dr.ItemArray(16).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@RstrQty", dr.ItemArray(17).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExecQty", dr.ItemArray(18).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@WorkQty", dr.ItemArray(19).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@CxlQty", dr.ItemArray(20).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@AccountNum", dr.ItemArray(21).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchMbrID", dr.ItemArray(22).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@ExchGrpID", dr.ItemArray(23).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchTrdID", dr.ItemArray(24).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@MemberID", dr.ItemArray(25).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@GroupID", dr.ItemArray(26).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@NTrdID", dr.ItemArray(27).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@Acct", dr.ItemArray(28).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@ExchTime", dr.ItemArray(29).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchDate", dr.ItemArray(30).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TimeSent", dr.ItemArray(31).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@TimeProcessed", dr.ItemArray(32).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@PA", dr.ItemArray(33).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@OrderNo", dr.ItemArray(34).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TTOrderKey", dr.ItemArray(35).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@IP", dr.ItemArray(36).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@FFT3", dr.ItemArray(37).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@FFT2", dr.ItemArray(38).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@SubmitTime", dr.ItemArray(39).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@SubmitDate", dr.ItemArray(40).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@TransID", dr.ItemArray(41).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@SessionID", dr.ItemArray(42).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@SeriesKey", dr.ItemArray(43).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@ExchangeOrderID", dr.ItemArray(44).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@Destination", dr.ItemArray(45).ToString()))
sqlServerCommand.Parameters.Add(New SqlParameter("@FlowDeliveryUnit", (dr.ItemArray(46))))sqlServerCommand.Parameters.Add(New SqlParameter("@TimeReceived", dr.ItemArray(47).ToString()))sqlServerCommand.Parameters.Add(New SqlParameter("@CallbackReceived", dr.ItemArray(48).ToString()))
sqlServerCommand.ExecuteNonQuery()Next
sqlServerConn.Close()
objConn.Close()
End Sub
Thanks for eveones input in advance.
Hi, does anyone know how to delete data from the SQL database by
calling the stored procedure in the Visual Basic.NET? Because I did the
Delete hyperlink bounded inside a datagrid. I have already displayed
the appointment date, time in the datagrid so I do not have to input
any values inside it. These are my stored procedures code for deleting:
ALTER PROCEDURE spCancelReservation(@AppDate DATETIME, @AppTime CHAR(4), @MemNRIC CHAR(9))
AS
BEGIN
IF NOT EXISTS
(SELECT MemNRIC, AppDate, AppTime
FROM DasAppointment
WHERE (MemNRIC = @MemNRIC) AND (AppDate = @AppDate) AND (AppTime = @AppTime))
RETURN -400
ELSE IF EXISTS
(SELECT MemNRIC
FROM DasAppointment
WHERE (DATEDIFF(DAY, GETDATE(), @AppDate) < 10))
RETURN -401
ELSE
DELETE FROM DasAppointment
WHERE MemNRIC = @MemNRIC
END
IF @@ERROR <> 0
RETURN @@ERROR
RETURN
DECLARE @status int
EXEC @status = spCancelReservation '2005-08-16', '1900', 'S1256755J'
SELECT 'Status' = @status
Can someone pls help? Thanks!
Hello -- I have a Huge Table Tab1 (160 Mill Rows). I have a script that Inserts and Deletes from this Tab1 (This Script runs for a good 4/5 Hrs).
When the script is being executed, No other session can even do a "SELECT TOP 10 * FROM Tab1"
How do i avoid this? Any "NOLOCK" Keywords i should be specifying in my Script?
Thanks in advance
Hi all.
I have an application that is using a SQL compact edition database to save/process information.
I run a test that is creating two threads:
1. one is inserting data in Table1
2. the other one is deleting records from Table1
When I run the application, I get some exceptions on both threads saying that the insert/delete could not aquire a lock on the table.
After a while, when I try to connect to the database I get an exception saying that the database file might be corrupted.
Any thoughts?
Thanks.
I have created a single Data Flow Task that reads a set of records from a source table and then makes determinations whether to insert, update or delete from a destination table. The data is basically being copied from one database to another with a small amount of data manipulation and lookups. The problem seems to be that when running the task, even a small amount of records read from the source table seem to take a long time for the task to finish. I feed the records into a Script Component (the brains) that sorts the records to three separate outputs. I use OLE DB Commands to perform the DELETE and UPDATE and an OLE DB Destination for INSERT. I thought that by using three separate database connections would help, but it just appears to be locked while trying to perform these commands against the same table.
Is there a way to control or route these three record sets in such a way as to perform them sequentially?
I know it's a bit of a simple question for some of you, but I'm just learning SSIS (but I like it!).
Thanks!
Jeff Tolman
E&M Electric
got a blank mssql 2005 express database. my table name is aspnet_IPNUmber. got two (2) columns IPNumberStart and IPNumberEnd both varchar(Max).
could somebody make a sample stored procedure for me that will insert the following records? im still learning how to make stored procs and my webhost only allow creating database in my domain but not uploading my database.
977600512
977666047
977731584
977764351
1024000000
1024032767
1024334848
1024334911
1024361504
1024361727
1024361760
1024361775
1024361792
1024361799
1024361824
1024361839
1024361984
1024362495
1024365824
1024366335
1024368128
1024368383
1024369408
1024369919
1024370688
1024371455
1024372224
1024372479
1024373248
1024373503
1024373888
1024374015
1024376192
1024376319
1024376480
1024376511
1024376832
1024393215
1025277952
1025294335
1062222976
1062223039
1062244312
1062244319
1062262784
1062263039
1064211840
1064211967
1072922624
1072922879
1072926720
1072926975
1072934400
1072934655
1072934944
1072934975
1072935680
1072935807
1072936448
1072936959
1074757800
1074757807
1077003688
1077003695
1078428256
1078428263
1079387904
1079388159
1079406080
1079406591
1081582080
1081582087
1081583216
1081583231
1081584168
1081584191
1081589104
1081589111
1091692644
1091692653
1093057408
1093057423
1103678544
1103678551
1103678656
1103678719
1104003456
1104003583
1104265216
1104265727
1104492288
1104492543
1104881088
1104881151
1105153216
1105153279
1106484352
1106484415
1106564608
1106564863
1113643148
1113643157
1113644092
1113644121
1114520064
1114520319
1114520576
1114520831
1120306176
1120306943
1120307968
1120308223
1120310016
1120310783
1120311808
1120312447
1120312576
1120312831
1121469912
1121469919
1122125979
1122125988
1139015776
1139015783
1139016000
1139016063
1211605088
1211605103
1211608032
1211608047
1247174064
1247174071
1247174368
1247174383
1254967080
1254967087
1254973664
1254973671
1266551520
1266551527
1266570304
1266570319
1432131584
1432133631
1946173664
1946173679
1946173952
1946174015
1946176512
1946176767
1949466624
1949499391
1950545920
1950547967
1950648320
1950650367
1952251904
1952284671
1960207360
1960207615
1966784512
1966792703
1969694720
1969696767
1969811456
1969815551
1984151552
1984153599
1985480704
1985482751
1986404352
1986406399
1996627968
1996630015
1998290944
1998299135
2030108672
2030125055
2033377280
2033385471
2033582080
2033614847
2033623040
2033625087
2033893376
2033909759
2036334592
2036465663
2038366208
2038374399
2046951424
2047082495
2050084864
2050088959
2050228224
2050490367
2056273920
2056290303
2072528896
2072530943
2075148288
2075150335
2079508480
2079510527
2080800768
2080817151
2081652736
2081685503
2085814272
2085847039
2087190528
2087452671
2090737664
2090745855
2094596096
2094628863
2097479680
2097545215
2101116928
2101149695
2111045632
2111078399
2113683520
2113683679
2113683744
2113684095
2113684176
2113684255
2113684272
2113684431
2113684440
2113684479
2113684544
2113684735
2113684992
2113685007
2113685024
2113685047
2113685120
2113685231
2113685248
2113686079
2113688320
2113689087
2113690112
2113690367
2113691904
2113692031
2113692160
2113692415
2113694720
2113695231
2113695488
2113695743
2704978756
2704978759
2782658560
2782724095
3231309056
3231311103
3233590784
3233591039
3233668864
3233669119
3236102144
3236106239
3262474113
3262474113
3262474143
3262474143
3262474193
3262474193
3278940156
3278940159
3278942516
3278942519
3278942612
3278942615
3325562880
3325566975
3326118524
3326118527
3326119248
3326119251
3326122972
3326122973
3334995968
3335000063
3389001728
3389005823
3389020928
3389021183
3389092352
3389092863
3389259776
3389263871
3389579264
3389587455
3389788416
3389788927
3389936896
3389937663
3391663104
3391664127
3391722240
3391722495
3391906816
3391907839
3392109824
3392110335
3392110592
3392111103
3392111360
3392112127
3392112640
3392114175
3392446464
3392450559
3392741376
3392765951
3392799232
3392799487
3392856064
3392864255
3392931840
3392933887
3393011712
3393019903
3393302528
3393306623
3393560576
3393568767
3393609728
3393613823
3393695744
3393699839
3393744896
3393748991
3393822720
3393830911
3393910784
3393911807
3394079232
3394079743
3394125824
3394142207
3394279424
3394281471
3394347008
3394355199
3394507776
3394508799
3394527232
3394535423
3394682880
3394686975
3394832384
3394834431
3394879488
3394883583
3394910208
3394912255
3394928640
3394936831
3395002368
3395006463
3395059712
3395067903
3395280896
3395284991
3397027072
3397027327
3397070848
3397074943
3397156864
3397165055
3397263360
3397267455
3397394432
3397402623
3397763072
3397771263
3397793792
3397794303
3398004736
3398008831
3398074368
3398090751
3398612992
3398613503
3398638096
3398638111
3398638120
3398638135
3398638160
3398638167
3398638192
3398638207
3398638432
3398638447
3398638528
3398638575
3398638592
3398638655
3398638720
3398638847
3398638880
3398638911
3398639008
3398639231
3398639248
3398639263
3398639424
3398639455
3398639488
3398639615
3398646784
3398647039
3398902272
3398902783
3399655424
3399659519
3399729152
3399745535
3399786496
3399794687
3399826432
3399826943
3399924736
3399925759
3400336384
3400336639
3400337152
3400337407
3400515584
3400531967
3400998912
3401003007
3406565888
3406566143
3407987712
3407987967
3408066048
3408066303
3409396480
3409396735
3410804736
3410821119
3411052544
3411054591
3411152896
3411154943
3411156992
3411161087
3411212288
3411212799
3411320832
3411329023
3411509248
3411542015
3411806208
3411808255
3412251104
3412251119
3412322304
3412324351
3412606976
3412615167
3413106688
3413110783
3413262336
3413270527
3413344256
3413360639
3413574656
3413575679
3414155520
3414155775
3414230016
3414230527
3414376448
3414409215
3415803392
3415805951
3416131584
3416133631
3416301568
3416317951
3416473728
3416473855
3416487424
3416487487
3416719360
3416727551
3416735744
3416752127
3416850432
3416851455
3416981504
3416982527
3416983040
3416983551
3417047040
3417055231
3417178112
3417179135
3417243648
3417244671
3417374720
3417440255
3418163200
3418165247
3418243072
3418251263
3418326528
3418327039
3418396784
3418396799
3418399232
3418399359
3418399440
3418399455
3418401536
3418401599
3418401632
3418401647
3418401720
3418401727
3418401888
3418401903
3418649888
3418649951
3418652160
3418652163
3418652168
3418652171
3418652184
3418652207
3419412480
3419414527
3419783168
3419791359
3419881472
3419897855
3419924480
3419926527
3448257792
3448258047
3453373136
3453373143
3453374568
3453374583
3453374792
3453374807
3459338496
3459339263
3460948736
3460948799
3463602688
3463602943
3465438208
3465438463
3465475072
3465475583
3465476352
3465476607
3466044904
3466044911
3468076000
3468076031
3468085192
3468085199
3468085552
3468085567
3468096768
3468096895
3470660008
3470660015
3470660896
3470660903
3473096193
3473096447
3474193408
3474193663
3474193920
3474194431
3480605440
3480605695
3480605952
3480606207
3481029376
3481029631
3481032960
3481033727
3481039360
3481039871
3486607872
3486608127
3486615296
3486615551
3486624000
3486624255
3489738752
3489740799
3494454129
3494454158
3496290760
3496290767
3496292320
3496292335
3504922624
3504923391
3505119232
3505119487
3508082688
3508082943
3508098304
3508098559
3508100608
3508100863
3508281344
3508281599
3508286912
3508286927
3508337152
3508337663
3509834208
3509834223
3509836872
3509836879
3512562944
3512563071
3512563968
3512564095
3512565248
3512565503
3512577600
3512577631
3512590976
3512591103
3512592896
3512593151
3512598272
3512598527
3518895720
3518895727
3523297280
3523317759
3523477504
3523493887
3523502080
3523510271
3523559424
3523575807
3524132864
3524145151
3524263936
3524266495
3524266752
3524274175
3524274432
3524296703
3524747264
3524755455
3524763648
3524781791
3524781824
3524788223
3535380480
3535388671
3537190912
3537240063
3570076944
3570076951
3624298496
3624299519
3628154240
3628154303
3632480608
3632480615
3632481288
3632481295
3632483856
3632483863
3632484080
3632484087
3632485632
3632485647
3632490688
3632490695
3632494560
3632494567
3680124928
3680133119
3715719168
3715727359
3732799488
3732832255
3732865024
3732930559
I am getting a number of deadlocks when inserting and deleting items from the same table.
The delete statement has a U lock and awaiting an IX lock on an index that covers the column in the where clause.
The insert statement has a IX lock and awaiting a U lock on the same index.
The delete statement is deleting about 5000 rows, where as the insert statement is inserting a single row.
Both these statements are found in stored procedures being called from LINQ to SQL.
I am wondering if there is a way I can prevent the delete statement taking the U lock out?My thinking being if the delete didn't take out the U lock then it would not deadlock with the insert. Are there any hints I could use to avoid the particular lock above?
I have seen various examples of multiple updates causing a deadlock, which can be fixed by adding multiple indexes. However, as I am inserting and deleting rows I imagine that all the indexes will need to be updated by both operations.
I have inherited the architecture and don't have the time to redesign everything at present. My backup plan is to deprioritize the delete and build in a retry mechanism.
However, it would be really good if I could find a more elegant way to handle deleting and inserting rows at the same time.
Deadlock trace information below...
11/02/2015 22:21:26,spid21s,Unknown,waiter id=process1cc9c68558 mode=IX requestType=wait
11/02/2015 22:21:26,spid21s,Unknown,waiter-list
11/02/2015 22:21:26,spid21s,Unknown,owner id=process203f31b498 mode=U
11/02/2015 22:21:26,spid21s,Unknown,owner-list
11/02/2015 22:21:26,spid21s,Unknown,pagelock fileid=1 pageid=721673 dbid=6 subresource=FULL objectname=PerforceReports_Staging.dbo.DebugReport id=lock1663f5d900 mode=U
[Code] ....
I have two database(MYDB1 , MYDB2) on two different server's(SERVER1 , SERVER2) . I want to create an store procedure in MYDB1 on SERVER1 and get some data from a table of MYDB2 on SERVER2. How can i do this?
View 5 Replies View RelatedHi,
Uses: SQL Server 2000, ASP.NET 1.1;
I've the following tables which has a 1:M relationship within them:
Contact(ContactID, LastName, FirstName, Address, Email, Fax)
ContactTelephone(ContactID, TelephoneNos)
I have a webform made with asp.net, and have given the user to add maximum of 3 telephone nos for a contact (Telephone Nos can be either Mobile or Land phones). So I've used Textbox's in the following way for the appropriate fields:
LastName,
FirstName,
Address,
Fax,
Email,
MobileNo,
PhoneNo1,
PhoneNo2,
PhoneNo3.
Once the submit button is pressed, I need to take all of this values and insert them in the tables via a Single Stored Procedure. I need to know could this be done and How?
Eagerly awaiting a response.
Thanks,
Hi All,
I want to insert data using a stored proc. Can anyone tell me the correct syntax for inserting data into a table using a stored proc?
Thanks
Hi to all..
I am new to ASP.Net, I want coding for inserting data in to SQL server 2005 that code contain the following criteria.
1.ASP.Net using C#.Net.
2.Using Stored Procdure.
3.the connetion string ,command , Data reader is in the same class. this class will be reusable for other page also without modifying any thing in it.
Please Help me.
Advance thanks.
Can anyone tell me how to access data from Stored Procedures using data adapters? My task is to select a row which is valid with data particular value. Suppose i had to get all values of particular user after validating username and password. Can anyone give me some hint regarding store procedure and retriving data from stored procedure using data adapters ? How can i bind data to dropdownbox of one field in the table using datasets and data adapters? How can i insert data in database using data adapters?Can any one solve this?
View 1 Replies View RelatedHello,
How can I get the name of the fields along with datatypes of a stored procedures.
Thanks in advance,
Uday.
Hi, I'm developing a fresh SQL DB which is result of a deep analysis of an old Access DB. THe thing is, this old one had very complex consultations to the Access tables, and some consultations were using another consultations as way to select some specific data. THe ideia in SQL is to avoid that too, however, there are some data that may serve exactly the same to some bigger stored procedures. This way, I have three options I guess: 1. Create every stored procedure making select queries directly to the table and it's done!2. Create auxiliary stored procedures which will select the redundant data, and when it is needed, another stored procedures call this one and use its returned data. (is this possible anyway?).3. I create a view to this redundant data, and the greater depth stored procedures access this data of the view when needed. I've heard, however, that a select to a view is slower than directly to the table, once the view adds an extra query to the process.. What is your guess on this issue of mine?I'm almost sure that option 1 is the best, however, I'd love to hear from you guys your opinion on this. The greater issue above this all is just one - performance. Thanks a lot!
View 3 Replies View RelatedHow do you run a stored procedure on PDW via SSIS? I've tried Execute SQL Task and Execute T-SQL Task but in both cases the task will run and complete almost immediately. Task shows success, no errors, but nothing happens in PDW. PDW admin console does not even register the query. Procedures run fine manually from SQL Server Object Explorer connection.
View 3 Replies View RelatedHow to use Stored Procedures in SSIS?
View 2 Replies View Relatedonly the tables and views are shown in the wizard (BIDS) thanks...
View 1 Replies View RelatedI want to know the differences between SQL Server 2000 storedprocedures and oracle stored procedures? Do they have differentsyntax? The concept should be the same that the stored proceduresexecute in the database server with better performance?Please advise good references for Oracle stored procedures also.thanks!!
View 11 Replies View RelatedI have my database: "RequestTrack"
My table (with its columns): "Request"RequestKey (automatically generated)..and the Primary KeyEntryDate (datetime)Summary (nvarchar)RequestStatusCodeKey (bigint)EntryUserID (nvarchar)EntryUserEmail (nvarchar)I am wanting to create a basic web form where my user interface has 3 text boxes and a Submit button:
txtUserID.TexttxtEmailAddress.TexttxtRequestSummary.Text
**After I hit the submit button the information will then be inserted into the database. Also the RequestStatusCodeKey will be MANUALLY typed in so that will not require the user to add that. Please please please help ! I've been searching online for days and looking at various websites and still havent found anything. I've found somethings but they went into too much depth with too much information. I am just wanting to stay basic but w/o using SQLDataSource Controls. I would like to be able to store a lot of data. Thanks for your help!!!
Hi all,
I am in the position where I have to transfer data from an old database
schema to a new database schema. During the transfer process alot of
logic has to be performed so that the old data gets inserted into the
new tables and are efficiently done so that all foreign keys are
remained and newly created keys (as the new schema is Normalised alot
more) are correct.
Is it best if I perform all this logic in a Stored Procedure or in C# code (where the queries will also be run)?
Tryst
I have defined a user defined data type. When I try to create a stored procedure specifying the column and user define data tpye I receive message
Server: Msg 2715, Level 16, State 3, Procedure spStoredproc, Line 0
Column or parameter #1: Cannot find data type udtcol1.
Server: Msg 2715, Level 16, State 1, Procedure spStoredproc, Line 0
Column or parameter #2: Cannot find data type udtcol2.
Server: Msg 2715, Level 16, State 1, Procedure spStoredproc, Line 0
Column or parameter #3: Cannot find data type udtcol3
Can you have user defined data types in stored procedures.
Store Procedure creation text
CREATE PROCEDURE spStoredproc
@col1 udtcol1,
@col2 udtcol2,
@col3 udtcol3
AS
INSERT INTO tblTempEmployee
(col1 , col2 , Col3)
VALUES (@col1 , @col2, @col3)
GO
SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS OFF
GO
Dave
Is there any array data type in SQL Server 7.0. I am using VB 6.0 with ADO 2.1. I am populating a MSFlexGrid with values that I pass to SQL Server one at a time and insert into the database. What I would like to do is pass the entire contents of the Grid at once to a stored procedure and let SQL do the processing so my routine is not going back and forth to the client. I did not find any documentation on any array data types in SQL. What is my best approach to this problem?
Thanks,
Dan Collins
Su writes "I'm trying to use a stored procedure to dynamically update a table whenever other staff in other departments update their do any changes to their databaseds. and thanks for your web site taught me how to pass table names as parameters. But I still have problems withe sql command. You have an example in your article ('dynamic sql 2'), showing how to do a sql SELECTION using a table name and a local variable. But the sql command only use a local variable of varchar type. I'm trying to do INSERT with local variables with different data types. For example:
CREATE PROCEDURE KPISU_F_TotalByF
@inputT_From varchar(10),
@inputT_To varchar(10),
@TableName varchar(1000)
AS
-----------------------------------------------------
--------input variable-------------------------------
DECLARE @inputTerm_From varchar(10),
@inputTerm_To varchar(10),
@sql_empty varchar(2000),
@sql_refresh varchar(2000)
----------------------------------------------------
IF EXISTS (select * from tempdb.dbo.sysobjects
where id LIKE object_id('tempdb..#tmpOTLTotalByF'))
DROP TABLE #tmpOTLTotalByF
CREATE TABLE #tmpOTLTotalByF (Faculty varchar(50),Term_From varchar(10), Total_G12 int, Total_G3 int, Total_G4 int, Total_Faculty int)
DECLARE @iFaculty varchar(50),
@iTerm_From varchar(10),
@iTotal_G12 int,
@iTotal_G3 int,
@iTotal_G4 int,
@iTotal_Faculty int
SET @iTotal_Faculty = 0
SET @iTotal_G12 = 0
SET @iTotal_G3 = 0
SET @iTotal_G4 = 0
DECLARE su_OTL_F_cursor CURSOR
FOR
SELECT Faculty, Term_From, SUM(Grades_12), SUM(Grades_3), SUM(Grades_4)
FROM #tmpOTLTotalByFaculty
GROUP BY Faculty, Term_From
OPEN su_OTL_F_cursor
FETCH NEXT FROM su_OTL_F_cursor INTO @iFaculty, @iTerm_From, @iTotal_G12, @iTotal_G3, @iTotal_G4
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @sql_refresh = 'INSERT '
SELECT @sql_refresh = @sql_refresh + @TableName
SELECT @sql_refresh = @sql_refresh + ' VALUES (' + @iFaculty + ', ' + @iTerm_From + ', ' + @iTotal_G12 + ', ' + @iTarget_12 + ', ' + @iTotal_G3 + ', ' + @iTarget_3 + ', ' + @iTotal_G4 + ', ' + @iTarget_4 + ', ' + @iTotal_Faculty + ')'
SET @iTotal_Faculty = 0
SET @iTotal_Faculty = @iTotal_G12 + @iTotal_G3 + @iTotal_G4
INSERT #tmpOTLTotalByF VALUES (@iFaculty, @iTerm_From, @iTotal_G12, @iTotal_G3, @iTotal_G4, @iTotal_Faculty)
Exec ( @sql_refresh)
FETCH NEXT FROM su_OTL_F_cursor INTO @iFaculty, @iTerm_From, @iTotal_G12, @iTotal_G3, @iTotal_G4
END
CLOSE su_OTL_F_cursor -----line 222
DEALLOCATE su_OTL_F_cursor
CLOSE su_OTL_T_cursor -----line 63
DEALLOCATE su_OTL_T_cursor
SELECT * FROM #tmpOTLTotalByF ORDER BY Faculty
SELECT * FROM KPISU_F_OTLTotalByF05 ORDER BY Faculty
GO
EXECUTE KPISU_F_TotalByF '2005', '2006', 'KPISU_F_OTLTotalByF05'
GO
----------------------------------------------------------
I got the following error message:
Server: Msg 245, Level 16, State 1, Procedure KPISU_F_TotalByF, Line 256
Syntax error converting the varchar value 'INSERT KPISU_F_OTLTotalByF06 VALUES (14-19 Academy, 2005, ' to a column of data type int.
-----------------------------------------------------------
I guess I could change all the columns in the table to data type of varchar. But are there any other way to solve this problem?
Many thanks.
Su"
Hi,
I am trying to write a stored procedure, which does a couple of things.
First thing is it looks up a persons Location based on an ID number, which is passed from an external Script. This will return four Values from a table.
I want to insert those four values into another table, along with another ID passed to the procedure from the same script.
My question is, what do I do to the script below to get the four values out of the first look up, into the insert?
The Field names returned from the SELECT are, AREA1, AREA2, AREA3, AREA4
Thanks
David
CREATE PROCEDURE UserAssign_Location
@UserID Int, @AreaID Int
AS
BEGIN
SET NOCOUNT ON;
SELECT * From Locations Where EntryID = @AreaID
INSERT INTO Members_Locations (UserID, Location1, Location2, Location3, Location4, Active)
VALUES (@UserID, 'AREA1', 'AREA2', 'AREA3', 'AREA4', 1)
END
GO
How to write Stored Procedures to load the Data Model from OLTP to DWH ?
View 9 Replies View RelatedHi,
This Might be a really simple thing, however we have just installed SQL server 2005 on a new server, and are having difficulties with the set up of the Store Procedures. Every time we try to modify an existing stored procedure it attempts to save it as an SQL file, unlike in 2000 where it saved it as part of the database itself.
Thank you in advance for any help on this matter