Tempdb Gets Out Of Control When Inserting Records
Jul 23, 2005
I have a very big table with 20 million records DistinctProjectionKey
which i join several times to different tables in this query.
select distinct distinctprojectionkeyid,dpk.MarketID,
dpk.Classificationid,
dpk.DistributorID,
dpk.ManufacturerID,
dpk.LocationID,
dpk.TimeID,P4.FACTOR as factor1,P3.FACTOR as factor2 ,P2.FACTOR as
factor3,P1.FACTOR as factor4
into Projectionfactors1
FROM DistinctProjectionKey dpk INNER JOIN D_Time t
ON t.TimeID = dpk.TimeID
INNER JOIN (select * from (select distinct
ClassificationID_Major,'fam' as lab from
StagingOLTP..ClassificationFlat) cf1)cf
ON cf.ClassificationID_Major = dpk.ClassificationID
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p4
ON t.TheDate = p4.TheDate
AND p4.Name = 'FAM'
AND cast(cf.Lab as varchar(20)) = cast(p4.Lab as varchar(20))
AND dpk.MarketID = p4.MarketID
AND p4.ManufacturerID IS NULL
AND p4.ClassificationID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p3
ON t.TheDate = p3.TheDate
AND p3.Name = 'fam'
AND cast(cf.Lab as varchar(20)) = cast(p3.Lab as varchar(20))
AND dpk.MarketID = p3.MarketID
AND p3.ClassificationID = dpk.ClassificationID
AND p3.ManufacturerID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p2
ON t.TheDate = p2.TheDate
AND p2.Name = 'fam'
AND cast(cf.Lab as varchar(20)) = cast(p2.Lab as varchar(20))
AND dpk.MarketID = p2.MarketID
AND p2.ManufacturerID = dpk.ManufacturerID
AND p2.ClassificationID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p1
ON t.TheDate = p1.TheDate
AND p1.Name = 'fam'
AND cast(cf.Lab as varchar(20))= cast(p1.Lab as varchar(20))
AND dpk.MarketID = p1.MarketID
AND p1.ManufacturerID = dpk.ManufacturerID
AND p1.ClassificationID = dpk.ClassificationID
the other table have fewer number of records .
I find that when I try to do the insert tempdb goes out of control ,it
grows above 100 GB?
Would anyone know the reason why and the solution to apply to avoid
this problem?
The other tables have fewer recods
Classification flat has 5000 records and projection default flat has
32652 records.
Ajay
Ajay
View 2 Replies
ADVERTISEMENT
Sep 6, 2000
Tempdb has grown to over 17 GB. It had no max growth limit set and actually took up all the disk space on the drive. I tried to run DBCC SHRINKDATABASE and received a bunch of errors about table corruptions. So, I found Brian Knight's post about stopping and restarting tempdb in minimal mode. I did that. It came back up and tempdb was correctly only 2 MB. It freed up 17 GB on the disk. Then, I stopped and restarted the service again, not in minimal mode, and it won't come back up. It has taken back that 17 GB of disk space. From the error log, I can see that it is stuck on rebuilding tempdb. Why is it trying to rebuild tempdb to 17 GB???
While in minimal mode, we did set the maximum growth limits to 1 GB for both data and log for tempdb, but that seemed to have no effect.
Any suggestions????
View 3 Replies
View Related
Mar 22, 2004
Hi all.
I have a db application that has been running fine for months. Volumes have been gradually increasing and one day the system locked up.
A stored proc that typically ran in 3 or 4 minutes never returned. The tempdb kept expanding to fill available disk space (100GB). This was the offending statement inside the stored proc:
INSERT INTO cpp (CPPDate,MerchantLink,ReportNumber,FromDate,ToDate ,TransThreshold,DayThreshold,CPPType)
SELECT S.CPPDate,S.MerchantLink,s.ReportNumber, s.FromDate,s.ToDate, S.OccurThresh,s.DaysThresh,'D'
FROM #stuff S, Trans T with (nolock), Supplier P with (nolock)
where T.MerchantNumber in (SELECT MerchantNumber FROM Merchant WHERE MerchantLink = s.MerchantLink)
AND T.TranDate >= S.FromDate
AND T.TranDate <= S.ToDate
AND T.LoadDate <= @ReportDate2
AND (T.SupplierNumber = P.SupplierNumber
AND T.IncludeInCpp = 'Y'
AND P.CountryNumber IN (SELECT CountryNumber FROM REPORTCOMBO WHERE ReportNumber = s.ReportNumber))
GROUP BY CPPDate,Merchantlink,ReportNumber, FromDate,ToDate, OccurThresh, DaysThresh
HAVING COUNT(DISTINCT T.AccountNumber) >= OccurThresh
I realize that a "group by" uses the tempdb, but can't figure out why it would go away rather than returning an error.
I have a workaround in place now. I split this big query into several steps using a cursor. (slower and clumsier, but it works) Statistics are updated daily, i have tried defragging, and reindexing with no success.
Any thoughts would be appreciated. If you need any more details, please let me know.
Thanks in advance.
View 3 Replies
View Related
Jul 18, 2006
Over weekend my tempdb grew 118 gig usually 1 gig.
I did shrink on it ...and its fine now.
But how to determine what could have caused this..
How can i say it was this process or this job ...any ideas.
Thanks
View 10 Replies
View Related
Oct 6, 2006
I set up a Sqldatasource control in 2.0 and I can retrieve data through a SQL Server connection from a stored procedure. My problem is when I set up the insert command object through the wizard for the Sqldatasource control with another stored procedure for inserting data and call the insert method of my Sqldatasource object i get nothing not even an error it just goes through the code like nothing was wrong and I don't get anything inserted. I don't know if this could be a problem but one of the parameters in the stored procedure is declared like this: @return tinyint output. I don't know how the Sqldatasource accounts for return parameters. Here is the code for the insert for the Sqldatasource object.<asp:SqlDataSource ID="sdsMain" runat="server" ConnectionString="<%$ ConnectionStrings:SN_CUSTOMERConnectionString %>"InsertCommand="uspSNOrder_Promo_Live" InsertCommandType="StoredProcedure" SelectCommand="uspOPFillPromo"SelectCommandType="StoredProcedure"><InsertParameters><asp:ControlParameter ControlID="ddlPromo" Name="promoid" PropertyName="SelectedValue"Type="Int32" /><asp:Parameter DefaultValue="1" Name="datasourceid" Type="Int32" /><asp:Parameter DefaultValue="0" Name="datasourcekey" Type="String" /><asp:Parameter DefaultValue="9" Name="salesroomid" Type="Int32" /><asp:Parameter DefaultValue="9999" Name="userid" Type="Int32" /><asp:ControlParameter ControlID="txtFName" DefaultValue="" Name="firstname" PropertyName="Text"Type="String" /><asp:ControlParameter ControlID="txtLName" Name="lastname" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtAddress" Name="address" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtCity" Name="city" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtState" Name="state" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtZip" Name="zip" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtPhone" Name="phone" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtEmail" Name="email" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="ddlStatus" Name="status" PropertyName="SelectedValue"Type="Int32" /><asp:Parameter DefaultValue="0" Direction="InputOutput" Name="return" Type="Byte" /></InsertParameters></asp:SqlDataSource>Thanks in advance
View 1 Replies
View Related
Nov 10, 2005
Using formview control, I'm trying to insert a record. In the process of inserting, I want to save the categoryid from a shared class. The code runs fine but categoryid gets saved as null...Any pointers?? [When I display, it shows the value]
thanks
protected void savebutton_click(object sender, EventArgs e) { //this statement runs fine under debug...but values do not get saved??? SqlDataSource1.InsertParameters.Add("@category", SharedValues.category.ToString()); SqlDataSource1.Insert(); }
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="itemid" DefaultMode="edit" OnDataBound="FormView1_DataBound"> <EditItemTemplate> Title: <asp:TextBox ID="titleTextBox" runat="server" Text='<%# Bind("title") %>'> </asp:TextBox><br/> Description: <asp:TextBox ID="descriptionTextBox" runat="server" Text='<%# Bind("description") %>' Rows="10" TextMode="MultiLine" Width="500px" Height="166px"> </asp:TextBox><br/> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </EditItemTemplate> <InsertItemTemplate> Title: <asp:TextBox ID="titleTextBox" runat="server" Text='<%# Bind("title") %>'> </asp:TextBox><br/> Description: <asp:TextBox ID="descriptionTextBox" runat="server" Text='<%# Bind("description") %>' Rows="10" TextMode="MultiLine" Width="500px" Height="166px"> </asp:TextBox><br/> <asp:label ID="categoryLbl" runat="server" Text='<%# SharedValues.category %>'></asp:label> <br/> <div class="actionbuttons"> <Club:RolloverButton ID="GreenRolloverButton3" CommandName="Insert" Text="Save" runat="server" OnClick="savebutton_click" /> <Club:RolloverLink ID="GreenRolloverLink2" Text="Cancel" runat="server" NavigateURL="Classifieds.aspx" /> </div> </InsertItemTemplate> </asp:FormView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" InsertCommand="insert into tads (title,[description], categoryid) values (@title,@description, @category)" SelectCommand="Select title, [description], categoryid from tads where itemid=@itemid" UpdateCommand="update tads set title = @title, [description] = @description where itemid = @itemid" > <SelectParameters> <asp:QueryStringParameter Name="itemid" QueryStringField="itemid" Type="Int32" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="title" Type="String" /> <asp:Parameter Name="description" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="title" Type="String" /> <asp:Parameter Name="description" Type="String" /> <asp:Parameter Name="category" Type="Int32" /> </InsertParameters></asp:SqlDataSource>
View 1 Replies
View Related
Jan 14, 2007
Hi,
My formview or gridview control stops updating or deleting a record once the record has a null value.
I have table tblTest with the following
pkID int NOT NULL **IDENTITY COLUMN** string1 varchar(30) string2 varchar(30)
I then create a SqlDataSource with the statement:
Select * From [tblTest]
I have the insert, update and delete statements generated, and choose optimistic concurrency. I add a couple records of dummy data.
I then drag a Formview control onto the page, and bind it to the SqlDataSource I just created. I then fire it up in my browser, and I can then update, insert and delete records. However, as soon as I update a record with a null value, I can no longer update or delete that record.
So, if I had a record in my FormView like:
string1: foo string2: bar
I can update and delete normally. And when I update to:
string1: foo string2:
the database correctly inserts a null value into string2. However, once that null is in the record, I can't change anything about the record. If I try to delete the record, the FormView will then display the previous record, but I can still page to the record that should have been deleted, and it still exists in the db. If I try to update the record, the edits I make will not keep and the process will fail silently.
What am I doing wrong? Should i be binding to a different object?
Regards,
Chris
View 5 Replies
View Related
May 2, 2006
I am working on an SSIS project where I create two flat files for submission to a data contractor. This contractor requires a control record be the first line in the file. I create the control record based on the table information being exported.
What I would like to know is, is it possible to utilize the Header Section of the Flat File Destination Editor to insert the control record? And, as it is dynamic, what kind of coding must I do in order to utlise this functionality?
Thanks.
View 4 Replies
View Related
Sep 13, 2006
Ok, I'm really new at this, but I am looking for a way to automatically insert new records into tables. I have one primary table with a primary key id that is automatically generated on insert and 3 other tables that have foreign keys pointing to the primary key. Is there a way to automatically create new records in the foreign tables that will have the new id? Would this be a job for a trigger, stored procedure? I admit I haven't studied up on those yet--I am learning things as I need them. Thanks.
View 4 Replies
View Related
Jun 25, 2007
Hi, all experts here,
I encontered a problem which did not allow me to select any thing from the temparary tables of the tempdb database. (e.g one of the temparary tables is #239E4DCF), why is that and how can we solve this problem? As I urgently need to look at this tempdb database, it is full. I am looking forward to hearing from you and thanks a lot in advance for your help.
With best regards,
Yours sincerely,
View 1 Replies
View Related
May 17, 2007
Hi,
I'm using SqlDataSource control.
Is there a way to know how many records a query has returned?
View 3 Replies
View Related
Jan 17, 2007
How to insert 100 record at a time by explicit inserting of identity column i.e.., by setting identity column to false
View 4 Replies
View Related
Feb 2, 2006
Hi,
I'm using VWD 2005 Express with SQL Server 2005 Express. I've created a page "create.aspx" which will be used to insert records into a table within the database.
I've used the DetailsView control together with a SqlDataSource control on the create.aspx page.
When I run the create.aspx page it retrieves the first record in the table of the database becuase the SqlDataSource is obviously performing a"Select * from Table" command.
I don't want this to occur. I want an empty page with no records. I know I can set a WHERE clause to a value that will never return any results but I don't beleieve this is an elegant way of doing things becuase I am 'hitting the database' for no reason other than to get the table structure poplutaed into the DetailsView control.
Questions:
1. Am I using the right controls? (in particular the SqlDataSource control)
2. Is there a better way of doing this?
Your advice is most appreciated. Thank you
View 7 Replies
View Related
May 29, 2006
pls i have this issue on inserting records into SQL SERVER Express. this is the code so far :-
imports system.data
imports system.data.sqlclient
Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim strConn As String = ConfigurationManager.ConnectionStrings("Connect1").ConnectionString
Dim ObjConn As New SqlConnection(strConn)
Dim strComm As String = "insert Products(ProductName,UnitPrice) values(@ProductName,@UnitPrice)"
Dim ObjComm As New SqlCommand(strComm, ObjConn)
ObjComm.Parameters.AddWithValue("@ProductName", txtprodname.Text)
ObjComm.Parameters.AddWithValue("@UnitPrice", SqlDbType.Money).Value = txtprice.Text
ObjConn.Open()
ObjComm.ExecuteNonQuery()
ObjConn.Close()
End Sub
End Class
The issue i have is that anytime i click the button to insert a new record, i get two records added to the database automatically
View 6 Replies
View Related
Jul 11, 2006
hi im a beginner trying to build an application that needs the user to enter some data into a table named Delievary. This table is related to another table named Products. The Products table has the following columns :- ProductsId - PK
ProductName
ProductPrice
Delievary table has the following columns
:- DelivaryId - PK
QuantityRecieved
ProductId - FK
i know to select i have to use inner joins but to insert is what i dont really know about. Please help me out
View 5 Replies
View Related
Jul 12, 2006
Ok i hav three tables namely customers, orders and products.
This are there structures Customers-: CustomerId-PK
FirstName
LastName
Address
Orders -: OrderId -PK
QuantityOrderd
OrderDate
CustomerId -FK
ProductId -FK
Products -: ProductId -PK
ProductName
UnitPrice
my question is that i need to relate them so that i can get info on a customer order
Thanks
View 1 Replies
View Related
Oct 26, 2006
Before I start driving myself nuts, I'd like to make sure my approach is correct.I want to create a simple job posting board.I have a text boxes for company name, email, job title, and job description, and a submit button.I created a table in my database called "JobPostings", with columns called "CoName", "CoEmail", "JobTitle", and "JobDesc"When someone fills out the fields and clicks submit, it will insert the new records.So,1. Is this the correct approach so far?2. What is the best way to display the job listings? A grid view?3. At submit time, how can I include that day's date?4. How can I get the records in the database to delete after 90 days?Thanks.
View 1 Replies
View Related
Feb 23, 2007
Hi, I am a rookie at sql and asp.net. I have another post is the asp.net section http://forums.asp.net/thread/1589094.aspx. Maybe I posted it in the wrong section.
I am collecting multiple rows from a gridview. I validated/confirmed I am capturing the correct values. How ever, I am having major problems passing these to an sql database. The problems that I know of is declaring my parameters correctly and then adding the values through a for each statement. I added the post over 30 hours ago with only me as the replier trying to refining or clarifying the problem. Part 1 is the code that works, part 2 is my problem, I have tried may different ways to resolve this but no luck.
Regards!
Protected Sub Botton1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click**************** PART1 **************************Dim gvIDs As String = ""Dim ddIDs As String = ""Dim chkBox As Boolean = FalseDim chkBox1 As Boolean = False'Navigate through each row in the GridView for checkbox items ddIDs = DropDownList1.SelectedValue.ToStringFor Each gv As GridViewRow In GridView1.RowsDim addChkBxItem As CheckBox = CType(gv.FindControl("delCheckBox"), CheckBox)Dim addChkBx1Item As CheckBox = CType(gv.FindControl("CheckBox1"), CheckBox) If addChkBxItem.Checked Then chkBox = True gvIDs = CType(gv.FindControl("TestID"), Label).Text.ToString Response.Write(ddIDs + " " + gvIDs + " ") If addChkBx1Item.Checked Then chkBox1 = True Response.Write("Defaut Item") End If Response.Write("<br />")End IfNext******************** Part 2 *****************************************************Dim cn As SqlConnection = New SqlConnection(SqlDataSource1.ConnectionString)If chkBox ThenTry Dim insertSQL As String = "INSERT INTO testwrite (TestLast, test1ID, TestDefault) VALUES (@TestLast, @test1ID, @TestDefault)" Dim cmd As SqlCommand = New SqlCommand(insertSQL, cn) cmd.Parameters.AddWithValue("@TestLast", DropDownList1.SelectedValue.ToString) cmd.Parameters.AddWithValue("@test1ID", CType(gv.FindControl("TestID"), Label).Text.ToString) cmd.Parameters.AddWithValue("@TestDefault, CType(gv.FindControl("CheckBox1"), CheckBox)) cn.Open()
For Each ..... Problems here also
Next
cmd.ExecuteNonQuery()Catch err As SqlException Response.Write(err.Message.ToString)Finally cn.Close()End TryEnd If
View 7 Replies
View Related
Jun 28, 2007
I have the Temporary table:ItemDetailID (int)FieldID (int)FieldTypeID (int)ReferenceName (Varchar(250))[Value] (varChar(MAX))in one instance Value might equal: "1, 2, 3, 4"This only happens when FieldTypeID = 5.So, I need an insert query for when FieldTypeID = 5, to insert 5 rows into the Table FieldListValues(ItemDetailID, [value])I have created a function to split the [Value] into a table of INTs Any Advice?
View 7 Replies
View Related
Nov 8, 2004
Hi,
I need to insert records in two tables, one is main table and another is child table. From my aspx page I need to pass info. for one records in main table, insert that record into main table, get the is of the inserted table.
Then insert 15 records in the child table.
Everything must be in a transaction, either everything works or everything fails. Should I do it with aspx or should I pass arrays to a stored procedure?
Thanks!
View 7 Replies
View Related
Feb 11, 2000
Hi!
Are there any parameters that could faster the insert statement?
Maybe some cache or buffer?
Michal
View 1 Replies
View Related
Apr 24, 2007
Hello,
I have a table with sixty columns in it, five of which define uniqueness for the records. Currently there are 190,775 records in the table. One of the records is a duplicate. I need to insert only the unique records from this table (all columns) into another table. I cannot use a unique nonclistered index with IGNORE_DUP_KEY in the destination table because of a problem I am having with the 'duplicate key was ignored' message. The destination table has a primary key with a clustered index on the same five columns.
How can I put together a SELECT statement that will give me all of the columns in the source table based on uniqueness of the five key columns?
Does my request make sense? Please let me know if you have questions.
Thank you for your help!
CSDunn
View 3 Replies
View Related
Jan 12, 2015
I'm faced with the task of creating a script that will do a series of inserts. The insert statements will look the same except for one value, which will differ for each insert.
For simplicity's sake, here is a table with some inserts:
CREATE TABLE
#MyTable (
MyPk INT IDENTITY,
MyValue VARCHAR(24)
)
[Code] ....
Rather than having to modify the string for each individual update statement, I'm hoping there is a simple way to create a variable (perhaps an array) which holds an indefinite number of values, then have a loop which automatically does an insert for each specified value in the array. Is something like this possible? Or is there a preferred industry standard for this sort of thing that I should use instead?
View 2 Replies
View Related
Feb 16, 2006
I'm getting a foreign key error as well as Indentity Insert error when I'm trying to run a stored proc that inserts values from another table..help!!
View 4 Replies
View Related
Jun 27, 2006
I'm having a problem finding step by step instructions in the few books I have on how to upload to your new table and database once those are set up.
I've got some data in an excel file, and I try to run the DTS wizard to create a package to upload the data from excel, but I can't seem to straiten out my data type problems.
How do I get my excel data types to match my table data types? It shouldn't be this hard to upload something so rudimentary. =(
View 5 Replies
View Related
Jul 10, 2007
hello everyone
I have a question about new record insertion. I have a SQL Database that I have cofigured as a publisher for a mobile database. I want to be able using the PDA to insert new Customers and synchronize the CE database with the SQL DB. But I encounter a problem with the column field rowguid that SQL inserts as a unique indentifier during the publication. It cannot accept null values and I can't insert a value using the keyboard since the value is generated by SQL.
So my impression is that you cannot use PDA to insert new records, only to update old ones. Is that true or I miss something??
If someone knows the answer please let me know.
Thank you in advanced.
View 8 Replies
View Related
Apr 1, 2004
Hi..
I really need a help.
Is there any way to insert multiple records into a table in one go?
I have a table named Fruit.
It contains FruitId,OwnerId,Colour
The list of colour is got from another table name FruitColour.
FruitColour Consists of 2 column, FruitName and Colour.
Is it possible to insert multiple records into Fruit table with one query if only the colour is changed.
Sample case
I have an Apple.
Fruit id=2
OwnerId=2
Colour -- > Select Colour From FruitColour where FruitName='Apple' (Will return multiple records)
I tried to insert using this query:
Insert into Fruit(FruitId,OwnerId,Colour) Values (2,2,Select Colour from FruitColour where FruitName='Apple').
Gives me this error
Subqueries are not allowed in this context. Only scalar expressions are allowed.
I need to do this because actually I am inserting multiple fruit at one time, and each have multiple colour. If I need to insert the colour one by one for each fruit it will takes a very long time.
Any suggestion are welcomed.
Thank you in advanced.
View 3 Replies
View Related
Mar 23, 2006
I am trying to insert a record in a SQL2005 Express database. I can use the sp fine and it works inside of the database, but when I try to launch it via ASP.NET it fails...
here is the code. I realize it is not complete, but the only required field is defined via hard code. The error I am getting states it cannot find "sp_InserOrder"
===
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection = Nothing
Dim trans As SqlTransaction = Nothing
Dim cmd As SqlCommand
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("PartsConnectionString").ConnectionString)
conn.Open()
trans = conn.BeginTransaction
cmd = New SqlCommand()
cmd.Connection = conn
cmd.Transaction = trans
cmd.CommandText = "usp_InserOrder"
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.Add("@MaterialID", Data.SqlDbType.Int)
cmd.Parameters.Add("@OpenItem", Data.SqlDbType.Bit)
cmd.Parameters("@MaterialID").Value = 3
cmd.ExecuteNonQuery()
trans.Commit()
=====
I get an error stating cannot find stored procedure. I added the Network Service account full access to the Web Site Directory, which is currently running locally on Windows XP Pro SP2.
Please help, I am a newb and lost...as you can tell from my code...
View 4 Replies
View Related
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
Nov 5, 2004
Hi,
I need to insert a record in a master table and 20 records in a child table. I want to do this using stored procedure. Is it better to do it in stored procedure? Have somebody already tried this? Or is there any sample that I can use?
Thanks a lot!
View 1 Replies
View Related
Nov 7, 2014
I am comparing names of people from a table without id field to a table that has those people along with their ids.
I have a select statements using different field combinations that fetches ids of these people and presents the result set like:
table1id,table1firstname,table2firstname,table1lastname,table2lastname
E.g.:
1 john john smith smith
1 john j smith smith
1 john jon smith smit
I want to be able to insert all the records from the result set into another table, like in the eg, but only excluding those ones that match all the above fields. How would I do this...
View 1 Replies
View Related
Mar 19, 2008
Folks:
I need help with this. When I run the below script (only select) it retrives around 130K records and gives me the output within 2 mins. Whenever I try to put the same output in a temp or permanent table it takes hours. Any Idea why?
SET NOCOUNT ON
DECLARE @ImportId INT
SET @ImportId = 5151
DECLARE @ResultXML XML
SET @ResultXML = (SELECT ResultXML FROM tbRequests WITH(NOLOCK) WHERE ImportId = @ImportId)
SELECT resultNode.value('(./DealName)[1]','VARCHAR(200)') AS DealName,
resultNode.value('(./CUSIP)[1]','VARCHAR(100)') AS CUSIP,
CASE WHEN resultNode.value('(./Vintage)[1]','VARCHAR(100)') = '' THEN NULL ELSE resultNode.value('(./Vintage)[1]','INT') END AS Vintage,
resultNode.value('(./PoolPoolType)[1]','VARCHAR(100)') AS PoolType,
CASE WHEN resultNode.value('(./PaidOff)[1]','VARCHAR(100)') = '' THEN NULL ELSE resultNode.value('(./PaidOff)[1]','BIT') END AS PaidOff
FROM @ResultXml.nodes('./WebService1010DataOutput') resultXml(resultXmlNode)
CROSS APPLY resultXmlNode.nodes('./Results/Result') resultNodes(resultNode)
===================================================================================
Same Query when trying to insert the records in a temp table it takes hours.
===================================================================================
SET NOCOUNT ON
DECLARE @ImportId INT
SET @ImportId = 5151
DECLARE @ResultXML XML
SET @ResultXML = (SELECT ResultXML FROM tbRequests WITH(NOLOCK) WHERE ImportId = @ImportId)
create table #TResults
([ID] [INT] IDENTITY(1,1) NOT NULL,
DealName VARCHAR(200),
CUSIP VARCHAR(100),
Vintage INT,
PoolType VARCHAR(100),
PaidOff BIT)
INSERT into #TResults (DealName,CUSIP,Vintage,PoolType,PaidOff)
SELECT resultNode.value('(./DealName)[1]','VARCHAR(200)') AS DealName,
resultNode.value('(./CUSIP)[1]','VARCHAR(100)') AS CUSIP,
CASE WHEN resultNode.value('(./Vintage)[1]','VARCHAR(100)') = '' THEN NULL ELSE resultNode.value('(./Vintage)[1]','INT') END AS Vintage,
resultNode.value('(./PoolPoolType)[1]','VARCHAR(100)') AS PoolType,
CASE WHEN resultNode.value('(./PaidOff)[1]','VARCHAR(100)') = '' THEN NULL ELSE resultNode.value('(./PaidOff)[1]','BIT') END AS PaidOff
FROM @ResultXml.nodes('./WebService1010DataOutput') resultXml(resultXmlNode)
CROSS APPLY resultXmlNode.nodes('./Results/Result') resultNodes(resultNode)
SELECT * FROM #TResults
============================================
Thanks !
View 7 Replies
View Related
Jul 23, 2005
I am trying to insert records via ASP, with a user that has only writeaccess to the table (db_datawriter, db_denydatareader).That way, if the server is ever compromised, the access informationstored in the source code's connection string will not allow anybody toactually read the database.The problem is that I would like to use ADO methods to insert the data(to prevent SQL injections), but I can't seem to get the rightconnection. It works in plain SQL, but I'd rather not use it.My current code looks like this:connection="Provider=SQLOLEDB.1;User ID=DBwriter;Password=XXX;DataSource=MYSERVER;Initial Catalog=MYDB;"set conn=server.createobject("ADODB.Connection")conn.mode=2 ' adModeWriteconn.open connectionSet rs = Server.CreateObject ("ADODB.Recordset")rs.Open "MYTABLE", conn, adOpenKeySet, adLockPessimistic, adCmdTablers.AddNewrs.Fields("testfield") = "TESTDATA"rs.UpdateAnd the error I get is:Microsoft OLE DB Provider for SQL Server (0x80040E09)SELECT permission denied on object 'MYTABLE', database 'MYDB', owner'dbo'.(If I use a User with read privileges in the connection stringeverything works fine.)
View 3 Replies
View Related