Query

MS SQL SERVER

    Next

  • 1. Webtask-Urgent
    I am using MS-Sql ServerI have created a webtask from Web Assitant Wizard . I have specified the location path as C:\Program Files\Microsoft SQL Server\ 80\Tools\WebPage1.htm but,now i want to change the location to d:\SqlWebtask\webpage1.htm How can i do that ?can any one please help ,me
  • 2. Error in Query Analyzer when I try to execute an update Msg 3624
    Server: Msg 3624, Level 20, State 1, Line 1 Location: p:\sql\ntdbms\storeng\drs\include\record.inl:1447 Expression: m_SizeRec > 0 && m_SizeRec <= MAXDATAROW SPID: 52 Process ID: 2032 Connection Broken When I try to execute: Update CFTVendor set requestItemCount = ( select count(*) from reqItem where lAssignSub_id = CFTVendorID ) + ( select count(*) from reqItem where CFTVendorID = lAtFaultSub_id ) + ( select count(*) from reqItem where CFTVendorID = lBackChrgSub_id ) where Status = 'MergP' and act ='MergR' This has worked before for me and just broke is this a server issue and do I have to change and parameters.
  • 3. Script Formatting Options
    Is there any way to set "Prefix the script with a check for existence" option (and the other options) when scripting objects from the database like we did for Query Analyzer? I like to script individual objects and include the drop code. QA had a full section under Tools => Options => Script => Script Formatting Options.

Query

Postby MC » Sat, 25 Mar 2006 07:14:05 GMT

Can someone help me for a SQL query to delete all the transactions from 2
SQL table?
Here is what I want to do.
"Go thru all the transactions in both table A and B
If table A has a record, delete this record first, then delete the same
record info from B

If table A has no record reference, continue and delete the record in B"

and so on.
Thanks



Re: Query

Postby Erland Sommarskog » Sat, 25 Mar 2006 08:23:54 GMT

MC ( XXXX@XXXXX.COM ) writes:

DELETE B
DELETE A

And most of all, don't delete row by row, delete all in one statement.




-- 
Erland Sommarskog, SQL Server MVP,  XXXX@XXXXX.COM 

Books Online for SQL Server 2005 at
 http://www.**--****.com/ 
Books Online for SQL Server 2000 at
 http://www.**--****.com/ 

Re: Query

Postby MC » Sat, 25 Mar 2006 23:06:17 GMT

My mistake,
Actually, I wanted to delete the records in both Table A and B, before Oct
4, 2004
MC





2



Re: Query

Postby Erland Sommarskog » Sun, 26 Mar 2006 08:26:28 GMT

MC ( XXXX@XXXXX.COM ) writes:

DELETE B
FROM   B
WHERE  EXISTS (SELECT * FROM A WHERE A.ID = B.ID
               AND A.purge_date < '20041004')
DELETE A purge_date < '20041001'

Since you did not provide CREATE TABLE statements for your tables, I 
had to make some things up.l

-- 
Erland Sommarskog, SQL Server MVP,  XXXX@XXXXX.COM 

Books Online for SQL Server 2005 at
 http://www.**--****.com/ 
Books Online for SQL Server 2000 at
 http://www.**--****.com/ 

Re: Query

Postby JP Bless » Wed, 29 Mar 2006 03:58:54 GMT

DELETE TableA.*, TableA.DateField
FROM TableA WHERE TableA.DateField < 10/4/2004









from
same
B"
 http://www.**--****.com/ 



Similar Threads:

1.Query using UDF joined to a sub query vs Temp Table to sub Query

I have a simple query question.  Currently I have a query that joins a UDF that returns a table to a sub query of a number of secondary tables.  This query seems to run forever, but if I dump the results of the udf into a temp table and use joined to the sub query the results are as expected.  Can anyone shed some light onto why?  Also is it possible to use the UDF in this manner with possible join hints to get the query return time I'm looking for?

2.SQL Server 2005 -- Internal Query Processor Error: The query processor could not produce a query plan

Hi all
I migrated a database from SQLServer 2000 (Standard edition) to
SQLServer 2005, standard, SP1, on Windows XP Prof, SP3
After migration I get the following error:

   Server: Msg 8624, Level 16, State 1, Line 6 
   Internal Query Processor Error: The query processor could not produce a query
plan. 

when I try to execute:

   insert into <table name> (Col1,Col2,Col3) values (val1,val2,val3)

I searched the internet and I found that similar errors where produced in SQL
2000
but this was a bug that was fixed in one of the service packs for 2000. Also
they involved complex query and anyway, it works in my SQL 2000. I found nothing
related to SQL 2005.

Any help appreciated

3.ADP code hangs while running the same query in query analyser works

I have got an updateable snapshot based on a view. When close the form, it 
automatically sends out the following script to update the underlying table.

exec sp_executesql N'UPDATE "arpos".."tafe_hdr" SET "ref2"=@P1 WHERE 
"seqno"=@P2 AND "created_date"=@P3 AND "enrolmentno"=@P4 AND "ord_ref"=@P5 
AND "ref1"=@P6 AND "ref2"=@P7 AND "notes" IS NULL AND "invno"=@P8', N'@P1 
varchar(6),@P2 int,@P3 datetime,@P4 varchar(12),@P5 varchar(4),@P6 
varchar(10),@P7 varchar(4),@P8 int', 'testts', 246, 'Feb  3 2003 
12:00:00:000AM', 'p02062693446', 'test', '0203000085', 'test', 246

This screen in ADP simply times out. In SQL Server locks, I can see that 
this connection is blocked by itself?! (how is that possible).

I run the same script in query analyser, the script completes under 1 sec.

Any idea what is going on?

I have a trigger on the underlying table that is being updated

CREATE TRIGGER ASAS_UPD_TAFE_HDR ON [dbo].[TAFE_HDR]
FOR UPDATE
AS
 if exists (select * from master.dbo.sysprocesses where program_name like 
'microsoft office%' and spid=@@spid)
 begin
  update
   a
  set
   a.transdate=b.created_date,
   a.ref2=b.enrolmentno,
   a.x_enrol_id=b.enrolmentno,
   a.ord_ref=b.ord_ref,
   a.ref1=b.ref1
  from
   dr_trans a inner join inserted b on
    a.jobno=b.seqno


  insert into asas_audit
   select
    'Update Invoice Header',
    system_user,
    host_name(),
    getdate(),
    invno
   from
    inserted
 end

I don't think it makes any difference. I have included it just in case if 
anyone can spot any problem here.

Thanks in advance


4.Showing Query Results from VBA SQL Query

Hello all,

I am running into an issue showing results from a VBA SQL query that I need 
to export to Excel.  Its nested within a loop sequence, and will run for each 
individual in a certain work group.

I have used the following code before and am just looking for they way to do 
it a VBA SQL dataset.

    DoCmd.OpenQuery "Query1"
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdCopy

5.make table query which lists all queries in db and their SQL state

Is there a way to create a query which returns all queries in the db and 
their SQL statement?  Or is there code that will do this for me?

Essentially, I'm envisioning a table which would have two columns:

Query Name | SQL

(Please don't mention Access' documenter feature as it is poorly designed 
for what I'm looking to do.)

Thanks!

Dave

6. save an query by sql code and deleting the saved query

7. Convert Access SQL Query to Excel MS Query

8. Query within a Query - SQL in VBA



Return to MS SQL SERVER

 

Who is online

Users browsing this forum: No registered users and 6 guest