Unusual Delete Query

Oct 3, 2000

We're trying to construct a query that deletes records containing 48 particular phone numbers from a large db. The 48 numbers are the entire contents of a smaller db, in a field of the same name as in the larger db (home_phone). We're using Sequel Server 7.0 and Access 97. The db's are in Access now. We failed in Acess and now would like to import into sql and try it there.
Thanks,
Tad McArdle

View 1 Replies


ADVERTISEMENT

Unusual Query

Jul 20, 2005

SQL Server 2000I need to compare 2 tables as follows:Table 1 - AccountsAcct#, Account NameTable 2 - Ledger(Among Others)Acct#,AccountNameI would like to create a view where the account number matches in both tables but the account name does not.I.e. Table 1:5000 MaintenanceTable 2:5000 Maintenance5000 Maintenance5000 Building Maintenancemy query view would display:5000 Building Maintenanceindicating there is a "Bad Record" and I would do some processing from there.FYI - I know I could prevent this easily, but I am actually comparing several databases with Table 2 data with a central Table 1 database.TIA-- Tim Morrison--------------------------------------------------------------------------------Vehicle Web Studio - The easiest way to create and maintain your vehicle related website.http://www.vehiclewebstudio.com

View 2 Replies View Related

Help - Unusual Problem

Aug 30, 2006

First, I can not change the data structure. I have a table called codesubsections that has an identity as the primary key. When a new codesubsection is entered the user can mark a formercodesubsection as a parent. The problem is that I need to be able to evaluate the table and identify the lowest CodeSubsectionID for a given row. so for instant when I look at row 7 it's text is 17 B p2 but because the CodeSubSectionID is not null I need to look at 6 then 5 and since 5 is null I need the text for 5,6,7 all to be 16:1 B. The only solution I have had any kind of luck with is to do a self join 3 times and coalesce the values up. See the code at the end. I am at my wits end, I had it working the other way assuming that the CodeSubSectionID was the parent of the record. This is the final piece of code on a project that is supposed to end tomorrow.

Any help is appreciated. I would normally post the procedures but I think that they are more confusing that the data explanation. This type of relationship is a first for me after 20 some years.





ID CodeSubSectionID Text

1 NULL 16:1 A

2 NULL 16:1 B

3 NULL 17 A

4 NULL 17 B p1

5 NULL 16:1 B

6 5 16:1 B

7 6 17 B p2

8 3 17 C

9 NULL 18

View 7 Replies View Related

SQL Mail, Unusual Message

Jun 9, 1999

I'm running SQL Server 6.5 (SP5a) on an NT4 server (SP3). I am using the Outlook Express account for SQLExecutiveCmdExec
which has all the requisite permissions. SQL Executive as well as SQL Server services are logging in under this account.
The server seems to be functioning normally in every other way (there's no production data on it yet).

When attempting to start SQL Main, the following lines appear in the Errorlog

1999/06/09 16:15:16.62 ods Starting SQL Mail session...
1999/06/09 16:15:16.64 ods Error : 17951, Severity: 18, State: 1
1999/06/09 16:15:16.64 ods Failed to start SQL Mail session.
1999/06/09 16:15:16.64 ods OS Error : 126, The specified module could not be found.

MSKB Does not have any information on this error message. Can anyone provide some insight as to what's going on please?

P.S. I have another server running SQL Mail with the same configuration with no problem.

View 2 Replies View Related

I Use SQL 2000, Can You Use One Delete Query To Delete 2 Tables?

Nov 26, 2007

this is my Delete Query NO 1
alter table ZT_Master disable trigger All
Delete ZT_Master WHERE TDateTime> = DATEADD(month,DATEDIFF(month,0,getdate())-(select Keepmonths from ZT_KeepMonths where id =1),0) AND TDateTime< DATEADD(month,DATEDIFF(month,0,getdate()),0)
alter table ZT_Master enable trigger All
 
I have troble in Delete Query No 2
here is a select statemnt , I need to delete them
select d.* from ZT_Master m, ZT_Detail d where (m.Prikey=d.MasterKey)  And m.TDateTime> = DATEADD(month,DATEDIFF(month,0,getdate())-(select Keepmonths from ZT_KeepMonths where id =1),0) AND m.TDateTime< DATEADD(month,DATEDIFF(month,0,getdate()),0)
I tried modified it as below
delete d.* from ZT_Master m, ZT_Detail d where (m.Prikey=d.MasterKey)  And m.TDateTime> = DATEADD(month,DATEDIFF(month,0,getdate())-(select Keepmonths from ZT_KeepMonths where id =1),0) AND m.TDateTime< DATEADD(month,DATEDIFF(month,0,getdate()),0)
but this doesn't works..
 
can you please help?
and can I combine these 2 SQL Query into one Sql Query? thank you

View 1 Replies View Related

How To Run Delete Query / Delete Several Rows Just By One Click ?

Feb 16, 2008

I'm using SqlDataSource and an Access database. Let's say I got two tables:user: userID, usernamemessage: userID, messagetextLet's say a user can register on my website, and leave several messages there. I have an admin page where I can select a user and delete all of his messages just by clicking one button.What would be the best (and easiest) way to make this?Here's my suggestion:I have made a "delete query" (with userID as parameter) in MS Access. It deletes all messages of a user when I type in the userID and click ok.Would it be possible to do this on my ASP.net page? If yes, what would the script look like?(yes, it is a newbie question) 

View 2 Replies View Related

Unusual Custom Datatable Scenario

Jul 20, 2007

For my website, I need to grab information from sources located on different servers. This will give me me various datasets that I need to combine into one, main dataset to then bind to my grid. Each dataset has the following fields:
Name || Blocked
I need the main dataset that is to be used on the grid to have the following structure:
Name || Blocked 1 || Blocked 2 || Blocked 3 || etc.......
The name field I can take from one of the datasets as the list of fields will be the same. However, I need to take the data from each of the blocked fields in the various datasets that are returned and then combine them to be the Blocked 1, etc columns that you can see above.
I'm making this post to ask for any advice on the best way to do this. Any info would be most appreciated.
Thanks,
James

View 11 Replies View Related

Help! Unusual SQL Server Activity With Sp_dbrename.

Apr 21, 1999

I recently renamed a database with sp_renamedb and created a new db with the same name as the old and restored the data into the new db. I put the old renamed db in single user mode to prevent data from becomming violated. After cycling SQL Server to flush the cache, I opened the floodgates for users. Our support line was full of calls from people saying "I'm getting the error 'Single User Mode in database DBORGINALDBNAME'. Any ideas why the application would be hitting the old database after I renamed and recycled the server?

View 1 Replies View Related

Extracting Unusual Date/times

Jan 18, 2008

I'm having a bit of trouble with dates/times. All I want to do is extract the contents of a table in an old Informix database and load it in to table in a SQL 2005 database.

The problem is that when I try to extract from the source table, I get the following error:

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E07 Description: "Error converting data type DBTYPE_DBTIMESTAMP to datetime.".Error: 0xC004701A at Dump Dacom Tables, DTS.Pipeline: component "mac_header" (181) failed the pre-execute phase and returned error code 0xC0202009.

It would have been nice if it could tell me what columns it was having trouble with. Anyway, I figured it out. There are two columns called time_open and time_close that contain times but no dates. This is how the source columns are configured:

time_open datetime hour to minutetime_close datetime hour to minute

This is a sample of what's in it:

select time_open, time_close from mac_headertime_open time_close07:07 07:0711:07 11:0707:07 07:0711:07 11:0706:55 06:55

This is a really old database. We started using it about 14 years ago. I can get an ODBC connection to it fine with any application except SQL Server. So, I have to do an OPENROWSET to get access to the data.

SELECT * FROM OPENROWSET('MSDASQL', 'Connection String Stuff', 'select * from dacom.mac_header')
Question 1: Why can't I get an ODBC connection to this Informix 5.10 database?

Question 2: How can I extract tables with this sort of data in it? I'm happy to store it as a normal date/time field in the destination SQL 2005 database, but I can't convert something that I can't extract.

Thanks

David Kirk

View 3 Replies View Related

Creating XML Output...unusual/impossible Format?

Sep 23, 2005

Hi all,

I'm Trying to replicate the creation of an "xml" file that is currently created using a C++ application. I want to take that application out of the picture, but need to create the same format XML file because a step later in the production process uses this file, and I cannot change it.

The output format I am looking for is:<?xml version="1.0" encoding="utf-8"?>
<FUNDS>
<AMRGX>
<NAME>AMERICAN GROWTH D</NAME>
</AMRGX>
<AHERX>
<NAME>AMERICAN HERITAGE FUND</NAME>
</AHERX>
<AMRVX>
<NAME>AMERICAN INVESTORS GROWTH FUND</NAME>
</AMRVX>
.
.
.
</FUNDS>The problem I am having is that I cannot seem to get the level/node of the fund symbol (AMRGX, AHERX, and AMRVX in the example above) as it needs to be. I think this must be some non-standard use of XML, since the tag is really the data itself (?)

The closest I have been able to get so far is:
<FUNDS>
<SYMBOL>AMRGX</SYMBOL>
<NAME>AMERICAN GROWTH D</NAME>
</FUNDS>
<FUNDS>
<SYMBOL>AHERX</SYMBOL>
<NAME>AMERICAN HERITAGE FUND</NAME>
</FUNDS>
.
.
.As you can see (hopefully) I am able to get the data I need but cannot get:
(1) the FUNDS tag(s) to be the very highest level/root.
nor (2) the SYMBOL part (tag label?) to be the actual variable stock fund.

Am I 'splaining this well enough? I don't necessarily need all the code, since I know I haven't given enough info to help with that, but my basic question is - - Is it possible to get a variable TAG based on the table DATA?

I want my SYMBOL tag to be the actual SYMBOL for the stock fund.

Confused? Not as much as I am *LOL* I am new to the use of all but XML EXPLICIT use, so any help would be appreciated - at least regarding my two formatting questions.

Yes, I have (and am still) searching around BOL for my answers, but so I have found nothing that helps me out. Meanwhile, suggestions are welcome!

Thanks!

View 6 Replies View Related

Unusual Error Message When Restoring Transaction Log

Nov 21, 2006

I was trying to restore a transaction log when I got this.
What does this mean? I can't find anything by Googling on the
'fixed' parts of the message.

The file 'xx' cannot be moved by this RESTORE operation

View 2 Replies View Related

Unusual Behavious Of An SSIS Package While Deployment

Feb 7, 2008


This is regarding one package where we are trying to deploy the package through €œSql Server deployment€? using .dtsx, .dtsConfig and manifest files, but after deployment the package is not found in €œmsdb€?. Instead it is reflecting in €œfile system€? folder. The same behavior is observed repeatedly when we tried to deploy the package.

We have seen such behavior only in this package. Please help us in solving the above scenario.

View 1 Replies View Related

DELETE Query - Can't JOIN. Need Sub-query?..

Mar 30, 2007

I need to run a DELETE query based on 2 tables. I can't use JOIN with delete queries, so how do I do this?

What I initially tried to do was:

Code:

DELETE FROM tblProductState
JOIN tblProduct
ON tblProduct.id_Product = tblProductState.id_Product
WHERE tblProductState.id_State = 54 AND tblProduct.id_ProductType = 1


Basically, I need to delete FROM tblProductState, WHERE tblProductState.id_State = 54 AND tblProduct.id_ProductType = 1

How can I do this without using JOIN. Use a sub-query? How?

Thanks

View 4 Replies View Related

Delete Query

Feb 28, 2008

Hi
I need some help on a query. I need to delete some records from a table, this table has a dependency to another table
Table 1: dbo.Accounts and Table 2: dbo.AccountsToUser
In the dbo.Accounts table there are
AccountId and OwnedByAccountId
54708002 54708001 54708003 54708001 65708002 65708001 65708003 65708001 54708001 2233440165708001 NULL
In the dbo.AccountsToUser there are
AccountId and UserId
65708002 10065708003 10165708003 10465708003 10654708001 19465708002 199
What I need is to delete every record from dbo.AccountsToUser that has an account connection to an account in the dbo.Accounts that has OwnedByAccount like NULL
So in the example above I should delete from dbo.AccountsToUser
65708002 10065708003 10165708003 10465708003 106
Since they are connected to 65708001 which has OwnedByAccountStatus like NULL
I could delete the records manually since the table is still hand able, but I need this to be a daily job so all help would be very nice
Thanks!
 

View 6 Replies View Related

Delete Query

Mar 31, 2008

Can any one please correct this query.Shall i write like this.Please correct this query.
 Delete globalDocs.dbo.gdoc_File set IsTrue=1 where FileID='abc'

View 6 Replies View Related

Is There Any Sql Query To Delete Any Particular Row

Apr 11, 2008

In sql server ...is there any opton to delete any particular row..
i have table student
no name
1    raja
2    pravin
3   abraham
 
suppose i what to delete 2nd row is there any option to delete whithout specifying no or name just only row(ie 2)
pl reply me....

View 6 Replies View Related

Delete Query?

Apr 12, 2008

Hi friends, I want to delete more than record using id.i pass group of id(with string concat) like 10|11|20|25. in stored procedure i want to delete corresponding record.10112025 any idea?Thanks,Durai 

View 3 Replies View Related

Delete Query

Feb 25, 2002

Below are 2 tables and data that I have.

Table1

col1col2col3
--------------------
11aaa
12bbb
13ccc
21ppp
22qqq
23rrr

Table2

col1col2
-------------
11
12
21

Now I want to delete all rows from Table1 which doesn't have a matching entry in Table 2. After the delete, this is what my Table1 data should be:

Table1

col1col2col3
--------------------
11aaa
12bbb
21ppp

Can some one give me a query to accomplish this? Thanks in advance for your help.

View 1 Replies View Related

Delete Query Help

Oct 7, 2006

Hi folks

Hoping someone can help me out with my query query!

I'm trying to write a script to do the following: delete everything from table1 where column A and B (of table1) does not match column A and B of table2

Any ideas??

Thanks as ever,
Georgia

View 1 Replies View Related

Delete Query ?

Aug 2, 2004

Hi,

Is this a valid SQL Server query :

DELETE FROM D FROM D WHERE LEFT JOIN H ON H.key=D:key WHERE H.key IS NULL

Please advise.

Thanks,
Sam

View 1 Replies View Related

Delete Query ?

Aug 2, 2004

Hi,

Is this a valid SQL Server query :

DELETE FROM D FROM D WHERE LEFT JOIN H ON H.key=D.key WHERE H.key IS NULL

Please advise.

Thanks,
Sam

View 2 Replies View Related

Help With Delete Query

Apr 5, 2007

Hi,

Not sure if this is possible in a delete query that is why I'm posting out of curiosity.

I have a table with one column (int datatype)

WorkItem
1
1
2
1
3
1

----(6 rows)

Can I delete the first record whose workitemid is 1

So that after the delete the resulting dataset in

WorkItemID
1
2
1
3
1

----(5 rows)

Thanks,

yumyum113

View 8 Replies View Related

Delete Query

May 25, 2007

hi all,
how do i perform this query?

DELETE FROM tblStkAdjDetail
WHERE (SELECT ItemStorageID FROM tblStkAdjDetail WHERE Status='NEW'
AND ItemStorageID NOT IN (SELECT ItemStorageId FROM tblTempTableForRecvPacking) )


~~~Focus on problem, not solution ¯(º_o)/¯ ~~~

View 10 Replies View Related

Query Regarding Delete

Feb 21, 2008

Hi All

I am beginner ot SQL Server.
I want to know that when we delete a row or a set of Rows from a table, it'll only make the space available for subsequent inserts into it or will the Delete also free the memory used by the table.

Suppose I am inserting customer records in the details table when the customer comes into the system. If i make a logic to delete the customer record from the table and insert into the backup table when it leaves the system(As the data inserted is quite large and my application queries into this table at each transaction). Will it help in optimizing the SQL Queries or it is useless to do so.

Thanks
Harsh Dhawan


Harsh Dhawan

View 4 Replies View Related

Delete Query

Aug 7, 2007

I have part of a stored proc that I need help with.
I need to figure out how to delete infro from the
tblManifest using the @ssnDelete variable.
I Have multiple records ffor the given above variable.

Would this need to loop in order to work and that is the solution for this.

I get ther following error when I run the full stored proc.
------------------------------

Msg 512, Level 16, State 1, Line 2

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
------------------------------


Here is the code fro part of the proceedure.
Thanks in advance.

Gene
----------------------------------------------------------

CREATE TABLE dbo.tblTempSSN(

ssn varchar(11) null);


OPEN SYMMETRIC KEY SymKeySSN

DECRYPTION BY CERTIFICATE CertSSN;

INSERT INTO tblTempSSN(ssn)

SELECT CONVERT(VARCHAR(11), DecryptByKey(s.SSN)) AS SSN

FROM tblSoldier s, tblManifest m

WHERE CONVERT(VARCHAR(11), DecryptByKey(s.SSN)) = m.ssn

CLOSE SYMMETRIC KEY SymKeySSN;


declare @ssnDelete varchar(11);

set @ssnDelete = (select (m.ssn) as ssn

from tblManifest m, tblTempSSN t

where t.ssn = m.ssn);


delete

from tblManifest

where ssn = '@ssnDelete';



DROP TABLE dbo.tblTempSSN;
----------------------------------------------------------

View 2 Replies View Related

Delete Query

Aug 7, 2007

I have part of a stored proc that I need help with.
I need to figure out how to delete infro from the
tblManifest using the @ssnDelete variable.
I Have multiple records ffor the given above variable.

Would this need to loop in order to work and that is the solution for this.

I get ther following error when I run the full stored proc.
------------------------------

Msg 512, Level 16, State 1, Line 2

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
------------------------------


Here is the code fro part of the proceedure.
Thanks in advance.

Gene
----------------------------------------------------------

CREATE TABLE dbo.tblTempSSN(

ssn varchar(11) null);


OPEN SYMMETRIC KEY SymKeySSN

DECRYPTION BY CERTIFICATE CertSSN;

INSERT INTO tblTempSSN(ssn)

SELECT CONVERT(VARCHAR(11), DecryptByKey(s.SSN)) AS SSN

FROM tblSoldier s, tblManifest m

WHERE CONVERT(VARCHAR(11), DecryptByKey(s.SSN)) = m.ssn

CLOSE SYMMETRIC KEY SymKeySSN;


declare @ssnDelete varchar(11);

set @ssnDelete = (select (m.ssn) as ssn

from tblManifest m, tblTempSSN t

where t.ssn = m.ssn);


delete

from tblManifest

where ssn = '@ssnDelete';



DROP TABLE dbo.tblTempSSN;
----------------------------------------------------------

View 4 Replies View Related

SQL Query - Delete All Rows Bar The Last 10? Help Please!

Jan 6, 2008

Hi,
I'm really not very good at SQL sadly, so would really appreciate any help.
I'm basically working on a website that has a chatroom. I want it so the chatroom table only holds, say 15 lines of chat, then once a new line of chat is entered the last line in the table is deleted, so the table always has a maximum of just 15 rows.
The fields are:
MessageID
Poster
Message
DateTime
I've tried my best, but just don't know how to do it.
I suppose it's something like:
SELECT TOP 15 * FROM Chatroom ORDER BY MessageID DESC - this gives me the last 15 rows.
Then I need a delete statement to delete the rest?! Sorry, I am very bad at SQL, so any help would be great. This is written in a stored procedure.
Can the stored procedure pick up whether there are 15 or more rows in the table, and if so then delete all bar the newest 15 rows of chat?
To summarise: I want a stored procedure that checks if 15 or more rows exist, if they do then delete all bar the newest 15 rows.
Thanks,
Ricky

View 5 Replies View Related

Delete Query With Inner Join

Nov 21, 2005

Hallo,

Can anybody let me know what I need to change to make this query work:

delete
from a
inner b
on a.item = b.item

I get the error message "Incorrect syntax near the keyword 'inner'."

Thanks,
Stephen.

View 3 Replies View Related

Delete Query Using Join

Jun 5, 2007

I need to delete records from one table base on criteria from another table. The example below from the Northwind database shows exactly what I want to do. I want to delete the records from the employee table who a terrorityID of 30346 in the EmployeeTerritories table.

Can someone tell me how to write a delete statement that will delete the rows returned from the following SQL Statement? The sql statement will return one employee name. I would lke to delete that one employee from the employee table and I haven’t been able to figure out how to do it.

////////// Sql Statment
SELECT dbo.EmployeeTerritories.EmployeeID, dbo.EmployeeTerritories.TerritoryID
FROM dbo.EmployeeTerritories INNER JOIN
dbo.Employees ON dbo.EmployeeTerritories.EmployeeID = dbo.Employees.EmployeeID
WHERE (dbo.EmployeeTerritories.TerritoryID = N'30346')
////////// end of sql statement

Thanks
GEM

View 3 Replies View Related

Delete From 2 Tables With 1 SQL Query

Mar 23, 2004

I have 2 tables that are joined together by a primary key (Order Number). Can I use one SQL query to delete from both of the tables. One table contains the order information from a client (Order Number, Customer Name etc). The other table has order information (Order Number, Item Number, Quantity Ordered etc.)

I need one statement that will allow me to remove the items from both tables. Can this be done.

Thanks in Advance

Wes

View 6 Replies View Related

Error In Delete Query

Apr 7, 2004

What is the problem in :


DELETE FROM tblPickingTask
LEFT OUTER JOIN tblPickingSlip ON tblPickingTask.SPSID = tblPickingSlip.SPSID
WHERE tblPickingSlip.SPSID IS NULL


I whan to delete all record in tblPickingTask was not in tblPickingSlip

View 3 Replies View Related

Delete Query For Two Tables

Nov 26, 2013

I have two tables PROFILES & ROLE

CREATE TABLE PROFILES(
ID varchar(20) UNIQUE NOT NULL,
Name varchar(40) NULL,
Address varchar(25) NULL
)

[Code] ...

This query joins both the tables and gets displayed in a grid.

select P.ID, Name, Address, Role, Applications
from PROFILES P
Inner Join ROLE R
ON P.ID= R.ID

I need to write a delete query which deletes data from both the table in a single query.

View 3 Replies View Related

Complex Delete Query Help.

Jul 27, 2007

Hello,

I have a db with 4 tables are linked by different fields. I'll setup a general layout for you in hopes of getting some assistance with write a delete query based on a date range. T is table, f is field.

T1.F1 = T3.F1
T1.F2 = T2.F2
T1.F3 = T4.F3
T1.F4 = T2.F4 {DATE}

so as you can see, this will be an embedded delete of some type but I have to somehow cache the deleted values so that these values can be used for the parent delete (I think).

I'm new to this stuff so...let me know if my approach is wrong. Perhaps it was a poorly written db. I have to purge about 5GB worth of data.

Thanks in advance,
Sid.

View 2 Replies View Related







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