Duplicate Records Are Being Inserted With One Insert Command.

Jul 20, 2005

This is like the bug from hell. It is kind of hard to explain, so
please bear with me.

Background Info: SQL Server 7.0, on an NT box, Active Server pages
with Javascript, using ADO objects.

I'm inserting simple records into a table. But one insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same data as the previous insert incident, (except for the timestamp).

Here is an example. Follow the values of the 'Search String' field:

I inserted one record at a time, in the following order (And only one
insert per item):
airplane
jet
dog
cat
mouse
tiger

After this, I should have had 6 records in the table. But, I ended
up with 11!


Here is what was recorded in the database:

Vid DateTime Type ProductName SearchString NumResults
cgcgGeorgeWeb3 Fri Sep 26 09:48:26 PDT 2003 i null airplane 112
cgcgGeorgeWeb3 Fri Sep 26 09:49:37 PDT 2003 i null jet 52
cgcgGeorgeWeb3 Fri Sep 26 09:50:00 PDT 2003 i null dog 49
cgcgGeorgeWeb3 Fri Sep 26 09:50:00 PDT 2003 i null jet 52
cgcgGeorgeWeb3 Fri Sep 26 09:50:00 PDT 2003 i null jet 52
cgcgGeorgeWeb3 Fri Sep 26 09:50:22 PDT 2003 i null dog 49
cgcgGeorgeWeb3 Fri Sep 26 09:50:22 PDT 2003 i null cat 75
cgcgGeorgeWeb3 Fri Sep 26 09:52:53 PDT 2003 i null mouse 64
cgcgGeorgeWeb3 Fri Sep 26 09:53:06 PDT 2003 i null tiger 14
cgcgGeorgeWeb3 Fri Sep 26 09:53:06 PDT 2003 i null mouse 64
cgcgGeorgeWeb3 Fri Sep 26 09:53:06 PDT 2003 i null mouse 64

Look at the timestamps, and notice which ones are the same.

I did one insert for 'dog' , but notice how 2 'jet' records were
inserted
at the same time. Then, when I inserted the 'cat' record, another
'dog' record was inserted. I waited awhile, and inserted mouse, and
only the mouse was inserted. But soon after, I inserted 'tiger', and 2
more mouse records were inserted.

If I wait awhile between inserts, then no extra records are inserted.
( Notice 'airplane', and the first 'mouse' entries. ) But if I insert
records right after one another, then the second record insertion also
inserts a record with data from the 1st insertion.

Here is the complete function, in Javascript (The main code of
interest
may start at the Query = "INSERT ... statement):
----------------------------------------------------------------------
//Write SearchTrack Record ------------------------------------

Search.prototype.writeSearchTrackRec = function(){
Response.Write ("<br>Calling function writeSearchTrack
"); // for
debug
var Query;
var vid;
var type = "i"; // Type is image
var Q = "', '";
var datetime = "GETDATE()";
//Get the Vid
// First - try to get from the outVid var of Cookieinc
try{
vid = outVid;
}catch(e){
vid = Request.Cookies("CGIVid"); // Gets cookie id value
vid = ""+vid;
if (vid == 'undefined' || vid == ""){
vid = "ImageSearchNoVid";
}
}

try{
Query = "INSERT SearchTrack (Vid, Type, SearchString, DateTime,
NumResults) ";
Query += "VALUES ('"+vid+Q+type+Q+this.searchString+"',
"+datetime+","+this.numResults+ ")";
this.cmd.CommandText = Query;
this.cmd.Execute();
}catch(e){
writeGenericErrLog("Insert SearchTrack failed", "Vid: "+vid+"
- SearchString:: "+this.searchString+" - NumResults: "+this.numResults
, e.description);

}
}//end

-----------------------------------------------------------------
I also wrote a non-object oriented function, and created the command
object inside the function. But I had the same results.

I know that the function is not getting called multiple times
because I print out a message each time it is called.

This really stumps me. I'll really appreciate any help you can
offer.

Thanks,

George

View 2 Replies


ADVERTISEMENT

Duplicate Last Record When Using SqlDataAdapter.Update For Insert Command

Jun 24, 2007

I'm getting duplicate records for the last record in the datatable. No matter how much or how little my datatable contains row records, it always duplicate the last one for some reason. Is there something wrong with my code below? EXAMID pulling from another stored procedure, which is outputed back to a variable.
---Data Access Layer---- If dt.Rows.Count > 0 Then
'INSERT EXAM ROSTERInsertComm = New SqlCommandsqladapter = New SqlDataAdapterInsertComm = New SqlClient.SqlCommand("ExamOfficers_AddOfficerSpecificExamRoster", conndb)InsertComm.CommandType = CommandType.StoredProcedure
sqladapter.InsertCommand = InsertCommInsertComm.Parameters.Add("@examid", SqlDbType.Int)InsertComm.Parameters("@examid").Value = examidInsertComm.Parameters.Add("@officerid", SqlDbType.Int, 12, "Officer_UID")InsertComm.Parameters.Add("@reimburse", SqlDbType.Bit, 12, "ReimburseToDb")InsertComm.Parameters.Add("@posttest", SqlDbType.Int, 12, "Post_Test")InsertComm.Parameters.Add("@pqcdate", SqlDbType.DateTime, 12, "pqc_date")InsertComm.Parameters.Add("@pqcscore", SqlDbType.Int, 12, "pqc_score")
conndb.Open()
sqladapter.UpdateBatchSize = 100InsertComm.UpdatedRowSource = UpdateRowSource.Nonesqladapter.Update(dt)
InsertComm.ExecuteNonQuery()InsertComm.Dispose()
End If
----Stored Procedure----
ALTER PROCEDURE [dbo].[ExamOfficers_AddOfficerSpecificExamRoster]
@ExamID as int,@OfficerID as int,@reimburse as bit=NULL,@posttest as int=NULL,@pqcdate as datetime=NULL,@pqcscore as int=NULL
ASBEGIN SET NOCOUNT ON;
Insert Into Exam_Officers(EXAM_UID,Officer_UID,reimburse,post_test,pqc_date,pqc_score)values(@ExamID,@OfficerID,@reimburse,@posttest,@pqcdate,@pqcscore)
END

View 1 Replies View Related

Insert Command Fails When I Want To Insert Records In Data Table

Apr 20, 2008

On my site users can register using ASP Membership Create user Wizard control.
I am also using the wizard control to design a simple question and answer  form that logged in users have access to.
it has 2 questions including a text box for Q1 and  dropdown list for Q2.
I have a table in my database called "Players" which has 3 Columns
UserId Primary Key of type Unique Identifyer
PlayerName Type String
PlayerGenre Type Sting
 
On completing the wizard and clicking the finish button, I want the data to be inserted into the SQl express Players table.
I am having problems getting this to work and keep getting exceptions.
 Be very helpful if somebody could check the code and advise where the problem is??
 
 
<asp:Wizard ID="Wizard1" runat="server" BackColor="#F7F6F3"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"
DisplaySideBar="False" Font-Names="Verdana" Font-Size="0.8em" Height="354px"
onfinishbuttonclick="Wizard1_FinishButtonClick" Width="631px">
<SideBarTemplate>
<asp:DataList ID="SideBarList" runat="server">
<ItemTemplate>
<asp:LinkButton ID="SideBarButton" runat="server" BorderWidth="0px"
Font-Names="Verdana" ForeColor="White"></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle Font-Bold="True" />
</asp:DataList>
</SideBarTemplate>
<StepStyle BackColor="#669999" BorderWidth="0px" ForeColor="#5D7B9D" />
<NavigationStyle VerticalAlign="Top" />
<WizardSteps>
<asp:WizardStep runat="server">
<table class="style1">
<tr>
<td class="style4">
A<span class="style6">Player Name</span></td>
<td class="style3">
<asp:TextBox ID="PlayerName" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="PlayerName" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
 
<td class="style3">
<asp:DropDownList ID="PlayerGenre" runat="server" Width="128px">
<asp:ListItem Value="-1">Select Genre</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="PlayerGenre" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</td>
 
</tr>
</table>
  Sql Data Source
<asp:SqlDataSource ID="InsertArtist1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="INSERT INTO [Playerst] ([UserId], [PlayerName], [PlayerGenre]) VALUES (@UserId, @PlayerName, @PlayerGenre)"
 
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>">
<InsertParameters>
<asp:Parameter Name="UserId" Type="Object" />
<asp:Parameter Name="PlayerName" Type="String" />
<asp:Parameter Name="PlayerGenre" Type="String" />
</InsertParameters>
 
 
</asp:SqlDataSource>
</asp:WizardStep>
 
 Event Handler
 
To match the answers to the user I get the UserId and insert this into the database to.protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
 SqlDataSource DataSource = (SqlDataSource)Wizard1.FindControl("InsertArtist1");
MembershipUser myUser = Membership.GetUser(this.User.Identity.Name);
Guid UserId = (Guid)myUser.ProviderUserKey;String Gender = ((DropDownList)Wizard1.FindControl("PlayerGenre")).SelectedValue;
DataSource.InsertParameters.Add("UserId", UserId.ToString());DataSource.InsertParameters.Add("PlayerGenre", Gender.ToString());
DataSource.Insert();
 
}
 

View 1 Replies View Related

Insert That Drops Duplicate Records

Mar 23, 2007

I ought to know how to do this, but it escapes me at the moment. I need to write an insert statement for a table that will be based on a complex select query. The select query may return rows that are already in the target table. In that case, I don't want duplicates created, but I don't want the query to error, either. I can't remember how to set that up.

View 3 Replies View Related

Problem Of Duplicate Records With A Simple Insert Statement !

Oct 11, 2007

 
I am using a simple stored proc shown below which inserts a record and updates the same record field called SortID with the Primary Key Column data of the same record.Everything was working fine until few days back. The site has been deployed 2 years back and was LIVE ever since.
We have got thousands of records in this Credits table. The table field called SortID is used for moving the credits up and down.
My problem is now after 2 years of deploying the table has got duplicate records, suprisingly a same credit is appearing under different MemberID and with the same SortID.
How are these duplicate records inserted with a simple insert statement & update ??
Is this a Locking problem or Transaction problem I have no idea.
Any ideas will be of great help
Thanks in Advance
Stored Procedure Used

CREATE PROC SP_SC_INSERT (@memberID int,@title varchar(30),@dir varchar(30),@desc varchar(20))ASINSERT INTO [dbo].[Credits]([MemberID],[Title],[Director], [Description], )VALUES(@memberID,@title,@dir, @desc, )UPDATE Credits Set SortID = @@IDENTITY WHERE CreditID = @@IDENTITYGO 

View 4 Replies View Related

Duplicate Inserted Record

Nov 14, 2007

Hi EverybodyThis Code duplicate the record in the database, can somebody help me understand why that happen. Thanks a LOT    CompanyName:    <asp:textbox id="txtCompanyName" runat="server" /><br />Phone:<asp:textbox id="txtPhone" runat="server" /><br /><br /><asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" /><asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dsn %>"    insertcommand="INSERT INTO [items] ([smId], [iTitleSP]) VALUES (@CompanyName, @Phone)"    selectcommand="SELECT * FROM [items]">    <insertparameters>        <asp:controlparameter controlid="txtCompanyName" name="CompanyName" />        <asp:controlparameter controlid="txtPhone" name="Phone" />    </insertparameters></asp:sqldatasource> VBPartial Class Default2    Inherits System.Web.UI.Page    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click        SqlDataSource1.Insert()    End SubEnd Class ----------------------------------------------Yes is an Identity the Primary Key of the Table items   

View 2 Replies View Related

Duplicate Record Inserted. Weird.........

Jul 5, 2007

1 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
2 Dim sqlStr As String
3 Dim sqlStr2 As String
4 Dim myConnection As MySqlConnection = Nothing
5 Dim myCommand As MySqlCommand = Nothing
6 Dim myConnection2 As MySqlConnection = Nothing
7 Dim myCommand2 As MySqlCommand = Nothing
8 Dim myReader As MySqlDataReader = Nothing
9 Dim IC As String
10
11 IC = txtIC1.Text + "-" + txtIC2.Text + "-" + txtIC3.Text
12
13
14 Try
15 sqlStr2 = "SELECT * FROM User WHERE uLogin='" & txtUserName.Text.Trim() & "'"
16
17 ' Connection
18 myConnection2 = New MySqlConnection(ConfigurationManager.ConnectionStrings("dbConnection").ToString())
19 myConnection2.Open()
20 ' Command
21 myCommand2 = New MySqlCommand(sqlStr2, myConnection2)
22 ' Reader
23 myReader = myCommand2.ExecuteReader()
24 Catch ex As Exception
25 ' Exception Error Here
26 Response.Write(Err.Number & " - " & Err.Description)
27
28 End Try
29 ' Checking
30 If myReader.Read() Then
31
32
33 Label2.Text = "Username already exist. Please choose another username"
34 Label3.Text = "*"
35
36 Else
37
38 Try
39
40
41 sqlStr = "INSERT INTO userapplication(uaName,uaIC,) VALUE (?uName,?uIC )"
42
43
44
45 ' Connection
46 myConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings("dbConnection").ToString())
47 myConnection.Open()
48 'Command
49 myCommand = New MySqlCommand(sqlStr, myConnection)
50
51 myCommand.Parameters.AddWithValue("?uName", txtName.Text)
52 myCommand.Parameters.AddWithValue("?uIC", IC)
53
54
55 myCommand.ExecuteNonQuery()
56 myConnection.Close()
57 Response.Redirect("Register.aspx", False)
58
59 Catch ex As Exception
60 ' Exception Error Here
61 Response.Write(Err.Number & " - " & Err.Description)
62 Finally
63 ' Clean Up
64 If Not IsNothing(myCommand) Then
65 myCommand.Dispose()
66 End If
67 '
68 If Not IsNothing(myConnection) Then
69 If myConnection.State = Data.ConnectionState.Open Then myConnection.Close()
70 myConnection.Dispose()
71 End If
72 End Try
73
74
75 End If
76
77 End Sub
78
79
 
 above is my code for the user registration page.the code that i bold,which with number 55,56 and 57,are where the problem occur.
when it run,it run 55, then 57,then back to 55, then 57 again
means that my db hav duplicate record being insert
anyone know how to solve this problem?

View 2 Replies View Related

Duplicate Record Inserted With Stored Procedure

Feb 4, 2008

I'm calling the stored procedure below to insert a record but every record is inserted into my table twice. I can't figure out why. I'm using Sql Server 2000.  Thanks.CREATE PROCEDURE sp_AddUserLog(@Username varchar(100),@IP varchar(50))AS SET NOCOUNT ONINSERT INTO TUserLogs (Username, IP) VALUES (@Username, @IP)GO  Sub AddUserLog(ByVal Username As String)
Dim SqlText As String
Dim cmd As SqlCommand
Dim strIPAddress As String

'Get the users IP address
strIPAddress = Request.UserHostAddress

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
SqlText = "sp_AddUserLog"
cmd = New SqlCommand(SqlText)
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con

cmd.Parameters.Add("@Username", SqlDbType.VarChar, 100).Value = Username
cmd.Parameters.Add("@IP", SqlDbType.VarChar, 100).Value = strIPAddress

Try
con.Open()
cmd.ExecuteNonQuery()
Finally
con.Close()
End Try

End Sub 

View 7 Replies View Related

SQL 2012 :: Check Command That Ensures Only Certain Values Inserted In Table?

Jan 14, 2015

I am trying to create a check command that ensures only A'B','c','D','E','F','G and s1, s2 can be inserted in the table, is this even applicable? Heres my code:

Create Table GRADE (
GradeVARCHAR2(1) CONSTRAINT pk_Grade PRIMARY KEY
CONSTRAINT check_grade
CHECK (substr(Grade = 'A','B','c','D','E','F','G')),

Salary_Scale VARCHAR2(2) CONSTRAINT check_SScale
CHECK (substr(Salary_Scale = 'S1', 'S2')),
)
/

View 1 Replies View Related

Defining Command,commandtype And Connectionstring For SELECT Command Is Not Similar To INSERT And UPDATE

Feb 23, 2007

i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString()        test.InsertCommandType = SqlDataSourceCommandType.Text        test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) "                  test.InsertParameters.Add("roll", TextBox1.Text)        test.InsertParameters.Add("name", TextBox2.Text)        test.InsertParameters.Add("age", TextBox3.Text)        test.InsertParameters.Add("email", TextBox4.Text)        test.Insert() i am using UPDATE command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString()        test.UpdateCommandType = SqlDataSourceCommandType.Text        test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll                                                         123 "        test.Update()but i have to use the SELECT command like this which is completely different from INSERT and  UPDATE commands   Dim tblData As New Data.DataTable()         Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated                                                                                Security=True;User Instance=True")   Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn)   Dim da As New Data.SqlClient.SqlDataAdapter(Command)   da.Fill(tblData)   conn.Close()                   TextBox4.Text = tblData.Rows(1).Item("name").ToString()        TextBox5.Text = tblData.Rows(1).Item("age").ToString()        TextBox6.Text = tblData.Rows(1).Item("email").ToString()       for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me

View 2 Replies View Related

Check How Many Records Are Getting Inserted

Apr 24, 2008

i want to check how many records are getting inserted into my database per day..can some one help in creating a trigger which gives the count

View 7 Replies View Related

Help! Trigger Using &#34;inserted&#34; Not Inserting Some Records.

Oct 10, 2001

Hello all,

I really need your help now, and I know I can always count on this group for tough answers to tough questions. OK, here's my dilemma. I have my trigger, which upon a record being inserted into db1.table1, inserts the same record into db2.table2 (SQL 7 db on the same server). What's happening is only a few of the fields are getting over there, but most are ending up NULL or 0. Everything besides the following records are inserting into the other database table properly:

EventName
EventStatusID
NumberofDays
NumberofStores
PreferredDate1
PleaseContactFlag
EventStoreSelection
EventClusterID

Note: The following fields have their Default Value set to (0)
SystemID
EventStatusID
Coop
NewProductFlag
TVSupportFlag
RadioSupportFlag
FSISupportFlag
RollbackPricing
PleaseContactFlag

Default Value set to (1):
KitInformationID

Here is the trigger:

CREATE TRIGGER EmoesImport ON mc_events FOR INSERT
AS
IF @@ROWCOUNT<>0

BEGIN

SET IDENTITY_INSERT mcweb2.dbo.mc_events ON

DECLARE @SystemID int
DECLARE @EventID int
DECLARE @AccountID int
DECLARE @BillingContactID int
DECLARE @EventName varchar(100)
DECLARE @EventStatusID tinyint
DECLARE @Coop bit
DECLARE @CoopSupplier varchar
DECLARE @SamplesPerDay int
DECLARE @BrochuresPerDay int
DECLARE @AverageDailyMovement int
DECLARE @SalesGoal int
DECLARE @NumberofDays int
DECLARE @NumberofHours int
DECLARE @NumberofStores int
DECLARE @WeekNumber tinyint
DECLARE @PreferredHourID tinyint
DECLARE @PreferredHourother char(20)
DECLARE @PreferredDate1 varchar(20)
DECLARE @PreferredDate2 varchar(20)
DECLARE @NewProductFlag bit
DECLARE @TVSupportFlag bit
DECLARE @RadioSupportFlag bit
DECLARE @FSISupportFlag bit
DECLARE @RollbackPricing bit
DECLARE @PleaseContactFlag bit
DECLARE @EventStoreSelection tinyint
DECLARE @EventClusterID int
DECLARE @KitInformationID tinyint
DECLARE @KitDescription varchar(1000)
DECLARE @KitOther varchar(200)
DECLARE @MCProgNum varchar(7)
DECLARE @rowguid uniqueidentifier

SELECT @SystemID = SystemID FROM INSERTED
SELECT @EventID = EventID FROM INSERTED
SELECT @AccountID = AccountID FROM INSERTED
SELECT @BillingContactID = BillingContactID FROM INSERTED
SELECT @EventName = EventName FROM INSERTED
SELECT @EventStatusID = EventStatusID FROM INSERTED
SELECT @Coop = Coop FROM INSERTED
SELECT @CoopSupplier = CoopSupplier FROM INSERTED
SELECT @SamplesPerDay = SamplesPerDay FROM INSERTED
SELECT @BrochuresPerDay = BrochuresPerDay FROM INSERTED
SELECT @AverageDailyMovement = AverageDailyMovement FROM INSERTED
SELECT @SalesGoal = SalesGoal FROM INSERTED
SELECT @NumberofDays = NumberofDays FROM INSERTED
SELECT @NumberofHours = NumberofHours FROM INSERTED
SELECT @NumberofStores = NumberofStores FROM INSERTED
SELECT @WeekNumber = WeekNumber FROM INSERTED
SELECT @PreferredHourID = PreferredHourID FROM INSERTED
SELECT @PreferredHourother = PreferredHourother FROM INSERTED
SELECT @PreferredDate1 = PreferredDate1 FROM INSERTED
SELECT @PreferredDate2 = PreferredDate2 FROM INSERTED
SELECT @NewProductFlag = NewProductFlag FROM INSERTED
SELECT @TVSupportFlag = TVSupportFlag FROM INSERTED
SELECT @RadioSupportFlag = RadioSupportFlag FROM INSERTED
SELECT @FSISupportFlag = FSISupportFlag FROM INSERTED
SELECT @RollbackPricing = RollbackPricing FROM INSERTED
SELECT @PleaseContactFlag = PleaseContactFlag FROM INSERTED
SELECT @EventStoreSelection = EventStoreSelection FROM INSERTED
SELECT @EventClusterID = EventClusterID FROM INSERTED
SELECT @KitInformationID = KitInformationID FROM INSERTED
SELECT @KitDescription = KitDescription FROM INSERTED
SELECT @KitOther = KitOther FROM INSERTED
SELECT @MCProgNum = MCProgNum FROM INSERTED
SELECT @rowguid = rowguid FROM INSERTED

INSERT INTO mcweb2.dbo.mc_events
(SystemID,
EventID,
AccountID,
BillingContactID,
EventName,
EventStatusID,
Coop,
CoopSupplier,
SamplesPerDay,
BrochuresPerDay,
AverageDailyMovement,
SalesGoal,
NumberofDays,
NumberofHours,
NumberofStores,
WeekNumber,
PreferredHourID,
PreferredHourother,
PreferredDate1,
PreferredDate2,
NewProductFlag,
TVSupportFlag,
RadioSupportFlag,
FSISupportFlag,
RollbackPricing,
PleaseContactFlag,
EventStoreSelection,
EventClusterID,
KitInformationID,
KitDescription,
KitOther,
MCProgNum,
rowguid)
VALUES
(@SystemID,
@EventID,
@AccountID,
@BillingContactID,
@EventName,
@EventStatusID,
@Coop,
@CoopSupplier,
@SamplesPerDay,
@BrochuresPerDay,
@AverageDailyMovement,
@SalesGoal,
@NumberofDays,
@NumberofHours,
@NumberofStores,
@WeekNumber,
@PreferredHourID,
@PreferredHourother,
@PreferredDate1,
@PreferredDate2,
@NewProductFlag,
@TVSupportFlag,
@RadioSupportFlag,
@FSISupportFlag,
@RollbackPricing,
@PleaseContactFlag,
@EventStoreSelection,
@EventClusterID,
@KitInformationID,
@KitDescription,
@KitOther,
@MCProgNum,
@rowguid)

SET IDENTITY_INSERT mcweb2.dbo.mc_events OFF

END


TIA,

Bruce Wexler
Programmer/Analyst
IT Department
Mass Connections
Ph: (562) 365-0200 x1091
Fx: (562) 365-0283
http://www.massconnections.com

View 1 Replies View Related

Records Being Inserted Into Gaps Of Identity Col

Jan 17, 2008

I have a table with the following specifications:

[FutureArticleId] [bigint] IDENTITY(1,1) NOT NULL,
[cFutureArticleTitle] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[cDescription] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[gCategoryId] [bigint] NOT NULL,
[cKeyword] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[bIsDeleted] [bit] NOT NULL CONSTRAINT [DF_tbl_FutureArticle_bIsDeleted] DEFAULT ((0)),
[tOnCreated] [datetime] NOT NULL,
[tOnUpdated] [datetime] NULL,
[gCreatedBy] [bigint] NOT NULL,
[gUpdatedBy] [bigint] NULL,

After some insertions and deletion from the UI, obviously there are gaps in the FutureArticleId column which is an identity column.

However, sometimes while inserting the records the records are being inserted into the gap and not in the next available Identity value.

Is there any table setting which I need to do, to stop this.

Please let me know

Thanks
Ankit

View 3 Replies View Related

Transact SQL :: Records Inserted Missing

Apr 25, 2015

Am witnessing a very strange issue when i try to insert some records . I get the message in the SSMSĀ  like 5,10 etc rows affected. When i check for the same records in the table none of them is present.

This problem then automatically goes away after some time and all get backs to normal. I only have the access to that database no other user have the access. Totally confused about the all of a sudden new behavior of the database.

View 10 Replies View Related

T-SQL (SS2K8) :: Finding Last Records Inserted Into All Tables In A Database

Jul 27, 2015

I have a CRM database that has a lot of tables and would like to be able to extract the last 'x' records in descending order from each table based on a common a field 'modifiedon' that is in every table and is auto populated by the system.

View 4 Replies View Related

Maximum Number Of Records Per Second That Can Be Inserted Into SQLServer 2000.

Apr 7, 2006

Summary: Maximum number of records per second that can be inserted intoSQLServer 2000.I am trying to insert hundreds (preferably even thousands) of recordsper second in to SQLServer table (see below) but I am getting thefollowing error in the Windows Event Viewer Application log file:"Insufficent Memory......"And very few records were inserted and no errors where sent back viathe JDBC.By removing the indexes on the table we have stopped getting the errormessage and have managed to load the table at 300 records per second.However I have couple of questions:1) Are the indexes definitely to blame for this error and is thereanyway of getting around this problem i.e. keeping the indexes in placewhen inserting?2) How should I configure SQLServer to maximise the speed ofinserts?3) What is the limiting factor for inserting into SQLServer?4) Does anyone know of any metrics for inserting records? At wantpoint should we consider load balancing across DBs.I currently populate 1.6 million records into this table. Once againthanks for the help!!CREATE TABLE [result] ([id] numeric(20,0) NOT NULL,[iid] numeric(20,0) NOT NULL,[sid] numeric(20,0) NOT NULL,[pn] varchar(30) NOT NULL,[tid] numeric(20,0) NOT NULL,[stid] numeric(6,0) NOT NULL,[cid] numeric(20,0) NOT NULL,[start] datetime NOT NULL,[ec] numeric(5,0) NOT NULL,)GOCREATE INDEX [ix_resultstart]ON [dbo].[result]([start])GOCREATE INDEX [indx_result_1]ON [dbo].[result]([id], [sid], [start], [ec])GOCREATE INDEX [indx_result_3]ON [dbo].[result]([id], [sid], [stid], [start])GOCREATE INDEX [indx_result_2]ON [dbo].[result]([id], [sid], [start])GO

View 5 Replies View Related

Order Of Records In The INSERTED/DELETED Tables In A Trigger

Nov 29, 2007

We have an app that uses triggers for auditing. Is there a way to know the order that the records were inserted or deleted? Or maybe a clearer question is.... Can the trigger figure out if it was invoked for a transaction that "inserted and then deleted" a record versus "deleted and then inserted" a record? The order of these is important to our auding.

Thanks!
CB

View 1 Replies View Related

SQL Server 2012 :: Inserted / Updated Records Count For Logging?

Feb 13, 2015

Initially I had designed ETL using Dataflow task in SSIS , No I have converted into Store procedure using merge statement.

I am getting new records inserted, source records and deleted row count when I am running sqp manually.

In ssis simple I have used the rowcount transformation to capture the records.

below variable i have declared in SSIS Package.

User::etlArchiveLogId
User::sourcerecords
User::newrecords
User::changerecord

now I am incremental loading using Stored procedure below is the sp which is executing when task success and logs the records.

ALTER PROCEDURE [dbo].[usp_LogArchiveBBxEndTime]
@EtlArchiveLog_Id int,
@RowsSource int,
@RowsNew int,
@RowsChanged int,
@Sucessful bit,
@Description varchar(500)

[code]....

Now I want to log the variable records which I have declared in my stored procedure .how can I log it in table?

View 1 Replies View Related

Can I Debug/watch On The Trigger's INSERTED And DELETED Records/values?

Jan 25, 2006

When i debug a trigger is it possible to add a WATCHon the INSERTED or DELETED?I think not, at least I couldn't figure out a way to do so.Does someone have a suggestion on how I can see the values?I did try to do something likeINSERT INTO TABLE1(NAME)SELECT NAME FROM INSERTEDbut this didn't work. When the trigger completed and Iwent to see the TABLE1, there were no records in it.Are there any documents, web links that describe waysof debugging the trigger's INSERTED and DELETED?Thank you

View 11 Replies View Related

INSERT INTO - Data Is Not Inserted

Jul 20, 2005

hi thereCreated sproc - it stops dead in the first lineWhy ????Thanks in advanceCREATE PROCEDURE [dbo].[test] ASinsert into timesheet.dbo.table1 (RE_Code, PR_Code, AC_Code, WE_Date,SAT, SUN, MON, TUE, WED, THU, FRI, NOTES, GENERAL, PO_Number,WWL_Number, CN_Number)SELECT RE_Code, PR_Code, AC_Code, WE_Date, SAT, SUN, MON, TUE,WED, THU, FRI, NOTES, GENERAL, PO_Number, WWL_Number, CN_NumberFROM dbo.WWL_TimeSheetsWHERE (RE_Code = 'akram.i') AND (WE_Date = CONVERT(DATETIME,'1999-12-03 00:00:00', 102))GO

View 6 Replies View Related

Inserted Records Missing In Sql Table Yet Tables' Primary Key Field Has Been Incremented.

Jun 18, 2007

I have a sql sever 2005 express table with an automatically incremented primary key field. I use a Detailsview to insert new records and on the Detailsview itemInserted event, i send out automated notification emails.
I then received two automated emails(indicating two records have been inserted) but looking at the database, the records are not there. Whats confusing me is that even the tables primary key field had been incremented by two, an indication that indeed the two records should actually be in table.  Recovering these records is not abig deal because i can re-enter them but iam wondering what the possible cause is. How come the id field was even incremented and the records are not there yet iam 100% sure no one deleted them. Its only me who can delete a record.
And then how come i insert new records now and they are all there in the database but now with two id numbers for those missing records skipped. Its not crucial data but for my learning, i feel i deserve understanding why it happened because next time, it might be costly.

View 5 Replies View Related

How Do I Use Outout Inserted With A Insert Into Query?

May 20, 2008

I cannot find a query that works on google. I want to insert a record and get the identity key afterwards.
thanks

View 3 Replies View Related

Insert Row, Then Update Using Inserted Identity Issues..

Oct 25, 2007

hey everyone, I have the following SQL:

CREATE PROCEDURE [dbo].[sp_InsertItem]

@item_channel_id INT, @item_title VARCHAR(75), @item_link VARCHAR(75),
@item_description VARCHAR(150), @item_long_description VARCHAR(1000),
@item_date DATETIME, @item_type VARCHAR(20)

AS

IF (@item_type = 'article')
BEGIN

INSERT INTO items (

item_channel_id, item_title, item_link, item_description, item_long_description,
item_date, item_type

) VALUES (

@item_channel_id, @item_title, @item_link, @item_description, @item_long_description,
@item_date, @item_type

)

END

IF (@item_type = 'mediaItem')
BEGIN

DECLARE @new_identity INT
DECLARE @new_link VARCHAR(100)

INSERT INTO items (

item_channel_id, item_title, item_link, item_description, item_long_description,
item_date, item_type

) VALUES (

@item_channel_id, @item_title, @item_link, @item_description, @item_long_description,
@item_date, @item_type

)

SET @new_identity = @@IDENTITY
SET @new_link = @item_link + @new_identity

UPDATE items
SET item_link = @new_link
WHERE item_id = @new_identity

END
GO

Basically, what I am trying to do is this...

IF the item type is article, insert normally... which works fine...

however, if the item time is mediaItem, insert part of the item_link... (everything minus id.. eg: site.com/items.aspx?item_id=)... then once the row has been inserted, update that row, to make the link site.com/items.aspx?item_id=<new id>

however, when the sql runs the mediaItem code, it leaves the item_link field blank.

Why is this doing this?

Thanks all!

View 2 Replies View Related

Generate Insert Script Of Last Inserted Record

Apr 24, 2015

How to generate insert script of last inserted record in SQL SERVER Table???.. I want use this code for log entry purpose..

View 1 Replies View Related

How To Make Sure In An Insert Statement That The Vendor Being Inserted Does Not Exist?

Dec 3, 2006

I am using  INSERT into Vendors (.....) VALUES (....)    form of insert statement. How can I make sure that the insert fails if thie new vendor's vendorname exists?
I cannot create a unique index on 'VendorName' column since it is more than 900 bytes and SQL Server will not allow to create index on a column bigger than 900 bytes.

View 8 Replies View Related

Can INSERT Statement Also Return All Columns Inserted As Result Set

Jun 2, 2014

Can an INSERT statement also return all columns inserted as a result set? If so what clause of the INSERT statement does this?

View 3 Replies View Related

Get The Id Of Inserted Rows --&&> Insert Into Table1 Select * From Table 2 ?

Apr 17, 2008



hi

I want to do a "bulk" insert and then get the id (primary key) of the inseret rows:

insert into table1 select * from table2

If I get the value of the @@identity, I always get the last inserted record.

Any idea how to get the ids of all inserted values?

Thx

Olivier

View 13 Replies View Related

Duplicate Records

Jan 18, 2000

Is there a way to find duplicate records in a table using code. We have about 500,000 records in this table.
Thanks.

View 1 Replies View Related

Duplicate Records

Jan 27, 2005

Hi All,

How to check for the duplicate records in the table? Thanks.

View 1 Replies View Related

Duplicate Records

Jun 12, 2002

Yes, I know this subject has been exhausted, but I need help in locating the discussion which took place a few months ago.
Sharon relayed to the group a piece of software (expensive) which would help in my particular situation. I grabbed a demo and have gotten the approval for purchase. Unfortunately, I don't have the thread with me at work.

The problem:

Number Fname Lname Age ID
123 John Franklin 43 1
123 Jane Franklin 40 2
123 Jeff Franklin 12 3
124 Jean Simmons 39 4
125 Gary Bender 37 5
126 Fred Johnson 29 6
126 Fred Johnson 39 7
127 Gene Simmons 47 8

The idea would be to get only unique records from the Number column. I don't care about which information I grab from the other columns, but I must have those fields included.
If my resultant result set looked as follows, that would be fine. Or any other way, as long as all of the fields had information and there were only unique values in the Number field.

Number Fname Lname Age ID
123 Jeff Franklin 12 3
124 Jean Simmons 39 4
125 Gary Bender 37 5
126 Fred Johnson 39 7
127 Gene Simmons 47 8

If anyone remembers this discussion, mainly the date, I would really appreciate it.

Thanks

Gregory Taylor
MIS Director
Timeshares By Owner

View 1 Replies View Related

Duplicate Records

Jul 13, 2007

Hi,

I have a field called user_no

i want to find out which ones are duplicates in the user_no field

the data in user_no is like this

111-222-345-666

so there are 10,000 records in the table and i want to find out the duplicate records in them

can someone tell me how my query will be

todd

View 1 Replies View Related

Duplicate Records

Feb 17, 2008

I have two tables, one contains all work orders, the second contains records on work orders that are linked to customoer orders. I'm trying to create a query that will return specific fields from the table that contains orders in the linked order table, and only the work orders in the all order table that (work_order) do not exist in the linked order table (demand_supply_link). I have tried several queries and cannot get the results I desire. Here is the query I am currently trying.

SELECT DISTINCT WORK_ORDER.DESIRED_WANT_DATE as 'Want Date', DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID as 'WO Id',
WORK_ORDER.DESIRED_QTY as 'End Qty', DEMAND_SUPPLY_LINK.SUPPLY_PART_ID as 'Part Id', CUST_ORDER_LINE.CUSTOMER_PART_ID as 'Cust Part',
OPERATION.RESOURCE_ID as Resource, PART.DESCRIPTION as Description, CUSTOMER.NAME as Name
FROM ((((DEMAND_SUPPLY_LINK INNER JOIN CUST_ORDER_LINE ON DEMAND_SUPPLY_LINK.DEMAND_BASE_ID = CUST_ORDER_LINE.CUST_ORDER_ID)
INNER JOIN WORK_ORDER ON DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID = WORK_ORDER.BASE_ID)
INNER JOIN OPERATION ON WORK_ORDER.BASE_ID = OPERATION.WORKORDER_BASE_ID) INNER JOIN PART ON WORK_ORDER.PART_ID = PART.ID)
INNER JOIN (CUSTOMER INNER JOIN CUSTOMER_ORDER ON CUSTOMER.ID = CUSTOMER_ORDER.CUSTOMER_ID) ON CUST_ORDER_LINE.CUST_ORDER_ID = CUSTOMER_ORDER.ID
WHERE WORK_ORDER.DESIRED_WANT_DATE Is Not Null AND OPERATION.RESOURCE_ID in ('ASSY','FAB 1','PLAY TRK')
AND WORK_ORDER.STATUS='R'

UNION
SELECT distinct work_order.desired_want_date as 'Want Date', work_order.BASE_id as 'WO Id',
work_order.desired_qty as 'End Qty', work_order.part_id as 'Part Id', operation.resource_id as Resource,
part.description as Description
FROM WORK_ORDER INNER JOIN PART ON PART_ID=WORK_ORDER.PART_ID INNER JOIN OPERATION ON WORK_ORDER.BASE_ID=OPERATION.WORKORDER_BASE_ID
WHERE WORK_ORDER.DESIRED_WANT_DATE IS NOT NULL AND OPERATION.RESOURCE_ID IN ('ASSY','FAB 1', 'PLAY TRK')
AND WORK_ORDER.STATUS='R'

This is the error I receive:
Server: Msg 205, Level 16, State 1, Line 1
All queries in an SQL statement containing a UNION operator must have an equal number of expressions in their target lists.

The all orders table (work_order) will not have the other fields to link to as there is no customer order linked to them.

Can anyone help. Thanks!

View 14 Replies View Related

Duplicate Records

Feb 9, 2004

Hi

Can anyone tell me how to stop a SQL query displaying duplicate records within a table

Thanks Alot

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved