Access Code - DELETE Statement with DISTINCTROW and T-SQL
All,
I'm trying to rewrite Access Code to T-SQL Code. I understand how DISTINCTROW works in a SELECT statement but I'm not sure of the same in a DELETE statement.
Any ideas?
DELETE DISTINCTROW Order_detail.*
FROM Order_Master
INNER JOIN Order_detail
ON (Order_Master.OrderID = Order_detail.OrderID)
AND (Order_Master.OrderPartID = Order_detail.OrderPartID)
Thanks,
MS
Could we use this syntax to delete records of two tables in same query ?
DELETE DISTINCTROW TableA.*, TableB.* FROM
TableA INNER JOIN TableB ON TableA.Name = TableB.Name
No. You can delete only one table at a time.
If you are using SQL Server 2012, you can try Merge:
create table a (id int, name varchar(10))
insert into a values (1,'aName'), (2,'ABCName'), (3,'BBBName')
create table b(id int, name varchar(10))
insert into b values (1,'bName'), (2,'ABCName'), (3,'BBBName')
declare @t table ( name varchar(10))
Merge a as tgt
using b as src On tgt.name =src.name
When matched then
Delete
Output deleted.name into @t;
delete from b Where name in (select name from @t)
Select * from a
select * from b
drop table a,b
Similar Messages
-
Customer Statement with opening and closing balances
Dear Forum,
The users want to generate the Customer Statement with opening and closing balances like the traditional one. The statement now generated gives the list of all open items as on date, but the users want the statement with opening balances as on the date of the begining of the range specified and the closing balance at the end of the period for which the statement is generated. Is there a way to generate the same from the system.
Thanks for the help.
Regards,Hi,
SPRO> Financial Accounting (New) > Accounts Receivable and Accounts Payable > Customer Accounts > Line Items > Correspondence > Make and Check Settings for Correspondence
You can use the program RFKORD10 with correspondance type SAP06 for your company code
This program prints account statements and open items lists for customers and vendors in letter form. For account statements, all postings between two key dates, as well as the opening and closing balance, are listed.
Regards,
Gaurav -
The question says it all:
What Are The Minimum Permissions In Order An User To Be Able To Access User Profile Data With JavaScript And REST API.?
In the User Profile -> Permissions there is only the option for "Full Control".Hi Nikolay,
Thanks for posting your issue, you need to set permissions on User Profiles = Read. Kindly find the below mentioned URLs to get the code and more details on this.
http://www.vrdmn.com/2013/02/sharepoint-2013-working-with-user.html
http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html
http://sharepoint.stackexchange.com/questions/61714/sharepoint-2013-call-the-rest-api-from-sharepoint-hosted-app
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/04/09/how-to-query-sharepoint-2013-using-rest-and-javascript.aspx
I hope this is helpful to you, mark it as Helpful.
If this works, Please mark it as Answered.
Regards,
Dharmendra Singh (MCPD-EA | MCTS)
Blog : http://sharepoint-community.net/profile/DharmendraSingh -
FI Customer Account Statement with Debit and Credit Columns
Hi SAP Expert,
We are using form (developed from T-code: SE71) to send customer account statment for only open items this is working fine.
Now My wants customer account statement for all transactions but with debit and credit in a separate columns. is there any way we fulfill these kind of request?
if any particular logic then let me know please.
thanks in advance
b/r
prashant raneDear Vivek,
You logic is helpful can I apply this in SE71 form development?
Below is my customer layout format
Document # | Document Date | Reference | Debit Amt | Credit Amt |
In bottom toal Debit / credit balance figure
can I use any code/login is SE71 form or I will need to create any development report which involves user exit?
I am looking for SE71 optios first
thanks in advance
Prashant Rane -
Delete statement with where clause
Please tell me delete statement for deleting database records from a table with a where clause comprising on composit primary key.
Eg:-
How to delete from employee where a=1, b=1, c=1. Employee also have other columns like name,address etc.
Kindly reply?857452 wrote:
kindly give me example.There are examples in the manual. -
SQL statement with LIMIT and total count?
Hello,
I would like to know if it is possible to execute a single SQL statement that will return me a subset of data (for pagination purposes) that not only includes the subset of data for the page but the count of all available data. Can this be done so as to not take up the cpu and time it takes to essentially run two queries? One to get the subset and one to get the count? I think simply doing a subselect is not going to give me what I want in that we actually query twice.
There may be no way to do this other than that, but I wanted to check with the gurus here first. :)
Thanks,
Markselect *
from (
select i.*,
row_number() over(order by i) rn, -- used for
pagination
count(*) over(partition by 1) cnt -- total count
of rows found for this search
from mytable
where < PUT ALL LIMITING (i.e., "search") CONDITIONS
HERE >
where rn between 41 and 50 -- pagination clauseNice one
BUT of course it adds additional row in execution plan and takes additional time and CPU :)
I assume that it directly depends of course on returned result set and some other factors like available sort space but a simple test case on a table big which actually is 1.6 M rows like dba_source got following results:
here is the first one returning also count(*)
SQL> select *
2 from (
3 select i.*,
4 row_number() over(order by owner, name, type) rn
5 , -- used for pagination
6 count(*) over(partition by 1) cnt -- total count of rows found for this search
7 from big i
8 where owner like 'S%' and name like '%A%'
9 )
10 where rn between 41 and 45
11 /
OWNER NAME TYPE
LINE
TEXT
RN CNT
SYS ANYDATA TYPE
13
STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
41 999744
SYS ANYDATA TYPE
11
STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
42 999744
SYS ANYDATA TYPE
9
43 999744
SYS ANYDATA TYPE
7
They serve as explicit CAST functions from any type in the Oracle ORDBMS
44 999744
SYS ANYDATA TYPE
6
enable construction of the AnyData in its entirity with a single call.
45 999744
Elapsed: 00:00:41.02
SQL> ed
Wrote file afiedt.buf
1 select n.name, m.value from v$statname n, v$mystat m
2 where n.statistic# = m.statistic#
3* and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
SQL> /
NAME VALUE
physical reads direct temporary tablespace 35446
physical writes direct temporary tablespace 17723
RowCR attempts 0
SMON posted for dropping temp segment 0
sorts (memory) 36
sorts (disk) 1
sorts (rows) 1999596
OTC commit optimization attempts 0
8 rows selected.here is the second one returning only rows:
SQL> ed
Wrote file afiedt.buf
1 select *
2 from (
3 select i.*,
4 row_number() over(order by owner, name, type) rn
5 --, -- used for pagination
6 -- count(*) over(partition by 1) cnt -- total count of rows found for this search
7 from big i
8 where owner like 'S%' and name like '%A%'
9 )
10* where rn between 41 and 45
SQL> /
OWNER NAME TYPE
LINE
TEXT
RN
SYS ANYDATA TYPE
13
STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
41
SYS ANYDATA TYPE
11
STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
42
SYS ANYDATA TYPE
9
43
SYS ANYDATA TYPE
7
They serve as explicit CAST functions from any type in the Oracle ORDBMS
44
SYS ANYDATA TYPE
6
enable construction of the AnyData in its entirity with a single call.
45
Elapsed: 00:00:12.09
SQL> select n.name, m.value from v$statname n, v$mystat m
2 where n.statistic# = m.statistic#
3 and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
4 /
NAME VALUE
physical reads direct temporary tablespace 0
physical writes direct temporary tablespace 0
RowCR attempts 0
SMON posted for dropping temp segment 0
sorts (memory) 10
sorts (disk) 0
sorts (rows) 999812
OTC commit optimization attempts 0
8 rows selected.So execution time 41 sec vs 12 sec
sorts (rows) 1 999 596 vs 999 812
physical reads/writes direct temporary tablespace 35446/17723 vs 0/0
I assume that for a small overall returned row count it probably is OK, but for less restrictive search it can be quite deadly as before with two queries.
Gints Plivna
http://www.gplivna.eu -
Problem with provisioning and external SQL server connection
I am configuring IPAM 2012 R2 on a our management server. Completed the first step by enabling the feature. No issues.
Now I am on the Provisioning IPAM step. I get to the Configure Database step...
I choose Microsoft SQL server,
What should those values be in the Server name and Database name fields. Instructions show fqdn or ip address but that doesnt seem to be working for me.
I get the following error at the end of the Provisioning IPAM wizard,
IPAM Deployment failed with the following error.
Failed to connect to database server. Check the database name, connectivity and remote access.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)
You can restart this provisioning wizard from the IPAM overview page.
From the management server I have tested the SQL Connection with a udl file. I used myServer\myInstance and it works. It reports that I have made the Connection to the server and database with the sql credentials i have provided.
ThanksRan
into a problem with connecting to the DB on the SQL server from the IPAM server. The Dba and I checked the target SQL instance was enabled TCP and listening on a valid TCP port. SQL server was set to use port 1443 for incoming connections.
IPAM was set by default to use 1433.
Also used
netstat-n to identify issue and verified 1443 on SQL server was
being used. Made the correction under the IPAM provisioning wizard and connected to the database. Fixed.
Important note I was able to connect to the database with a .udlfile
without any issues
Also note that 2012 R2 IPAM only supports 2012 SQL Enterprise. Why? -
Update Statement With Decode and Business Dates
Hello everyone,
I need to write a UPDATE statement using business date rule. In general, the due date is 30 days from the checkout date. If the due date falls on a Saturday or Sunday then the loan period is 32 days.
I know that to test for a weekday, I'd need to use the to_char function in Oracle with the format of ‘D’. I did some research and found that to test which weekday November 12, 2007 falls on, I'd need to use the expression to_char(’12-NOV-2007’,’D’). This function returns a number between 1 and 7. 1 represents Sunday, 2 Monday, …,7 Saturday.
What I really would need to do is write one UPDATE statement using an expression with the Decode function and the to_Char function:
UPDATE book_trans SET due_dte = expression
These are the transactions that will need to be updated:
ISBN 0-07-225790-3 checked out on 15-NOV-2007 by employee 101(book_trans_id=1)
ISBN 0-07-225790-3 checked out on 12-NOV-2007 by employee 151(book_trans_id=2)
ISBN 0-201-69471-9 checked out on 14-NOV-2007 by employee 175(book_trans_id=3)
ISBN 0-12-369379-9 checked out on 16-NOV-2007 by employee 201(book_trans_id=4)
I manually calculated the due-dte and wrote update statement for each book_trans_id:
UPDATE book_trans SET due_dte = '17-dec-07' WHERE book_trans_id = 1;
UPDATE book_trans SET due_dte = '12-dec-07' WHERE book_trans_id = 2;
UPDATE book_trans SET due_dte = '14-dec-07' WHERE book_trans_id = 3;
UPDATE book_trans SET due_dte = '18-dec-07' WHERE book_trans_id = 4;
As you can see, it's very cumbersome and I'd just like to know how to incorporate everything in one Update statement:
UPDATE book_trans SET due_dte = expression
so that if due date falls on Saturday or Sunday, the loan period is 32 days; weekday, loan period is 30 days.
Any tips or help will be greatly appreciated. Thanks!Hi,
882300 wrote:
Hello everyone,
I need to write a UPDATE statement using business date rule. In general, the due date is 30 days from the checkout date. If the due date falls on a Saturday or Sunday then the loan period is 32 days. That's equivalent to saying that the due date is normally 30 days after the checkout date, but if the checkout date falls on a Thursday or Friday, then the due date is 32 days after the checkout date. I used this equivalent in the statement below.
I know that to test for a weekday, I'd need to use the to_char function in Oracle with the format of ‘D’. I did some research and found that to test which weekday November 12, 2007 falls on, I'd need to use the expression to_char(’12-NOV-2007’,’D’). This function returns a number between 1 and 7. 1 represents Sunday, 2 Monday, …,7 Saturday.That's just one way to find out the weekday, and it's error-prone because it depends on your NLS_TERRITORY setting. A more reliable way is to use 'DY' or 'DAY' as the 2nd argument to TO_CHAR. That depends on NLS_DATE_LANGUAGE, but you can explicitly set the language in the optional 3rd argument to TO_CHAR, which means your code will work the same no matter what the NLS settings happen to be. It's also easier to debug: you may have to think whether '1' means Sunday or Monday, but it's easy to remember that 'SUN' means Sunday.
What I really would need to do is write one UPDATE statement using an expression with the Decode function and the to_Char function:
UPDATE book_trans SET due_dte = expressionHere's one way:
UPDATE book_trans
SET due_dte = checkout_dte + CASE
WHEN TO_CHAR ( checkout_dte
, 'fmDAY'
, 'NLS_DATE_LANGUAGE=ENGLISH'
) IN ('THURSDAY', 'FRIDAY')
THEN 32
ELSE 30
END
WHERE book_trans_id IN (1, 2, 3, 4)
;This assumes that checkout date is a column in the same table. -
Update statement with CASE and banding
Hello Folks,
I am stuck and am going nowhere.
I have two tables
MinuteCategory
Minute
MinuteCategory
MinuteLookup
MinuteCategoryId (surrogate key)
MinuteLow
MinuteHigh
MinuteCategory
Sample from Minute Lookup table ..
1 1
15 <15 min
2 16
30 <30 min
3 31
45 <45 min
4 46
60 <60 minutes
5 61
75 <1 hour 15 minutes
I am trying to update the MinuteCategory column in the MinuteCategory table using the MinuteLookup table.
For example if the minute = 33 then the corresponding lookup value would be 3 (from the lookup table), because the
33rd minute falls in between 31 min and 45 min and the corresponding surrogate key is 3
Is this possible with an Update statement in SQL? The only thing i can think of is use case statement as the join key between
the two tables but i don't think it's going to work :(
UPDATE
SET MinuteCategory = ml.MinuteCategoryId
FROM MinuteCategory mc join MinuteLookup ml on mc.Minute =
CASE WHEN mc.Minute between ml.MinuteLow and ml.MinuteHigh THEN ml.MinuteCategoryId ELSE NULL
END
Would appreciate any help.
SSPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I have two tables <<
Have you read any book on data, so you have some idea what a “<something>_category” means? THINK!! A minute is unit of temporal measurement. By definition, it cannot be a category.
There is no such thing as a “<something>_category_id”; a data element is a “<something>_category” or a “<something>_id”, as per basic data modeling.
Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton.
CREATE TABLE Timeslots
(slot_start_time TIME(1) NOT NULL PRIMARY KEY,
slot_end_time TIME(1) NOT NULL,
CHECK (start_time < end_time));
INSERT INTO Timeslots --15 min intervals
VALUES ('00:00:00.0', '00:14:59.9'),
('00:15:00.0', '00:29:59.9'),
('00:30:00.0', '00:44:59.9'),
('00:45:00.0', '01:00:59.9'),
('23:45:00.0', '23:59:59.9');
Here is the basic query for rounding down to a time slot.
SELECT CAST (@in_timestamp AS DATE), T.start_time
FROM Timeslots AS T
WHERE CAST (@in_timestamp AS TIME)
BETWEEN T.slot_start_time
AND T.slot_end_time;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Remote file access doesn't work with Mac and Q10
I'm running the latest BlackBerry Link (version 1.20, build 7) and Mac OS X (version 10.9) software on my Mac Mini computer.
I setup BlackBerry Link for remote file access.
On my Q10 in File Manager I see my Mac computer but for some reason I don't see any folders. It's just a black blank screen. My carrier is Telus.
In link I chose folders to access. It seems like everything is setup properly and I still see only a black blank screen on my Q10.
Any Mac users have this issue?Me too. None of the sync functions/remote file access/wifi sync using BB Link are working for me. I have a Mac (10.8.5) and a BB Z10 (10.2.0.429). I hope BB comes up with a solution soon.
-
BACKUP failure with error code sqlcode: -2419 with DB2 and SuSeLinux
Hi,
I have scheduled an online backup for PRD into tape drive and it failed and gave an error mesage
> SQL2419N The target disk "/dev/st0" has become full row=1
Database error -2419
I have kept the new tape but still getting the same error, My OS is Suse Linux and Database: DB2 9.7 FP4
Please Help me with the solution
Regards.
RajuDear Raju,
Check this & set the "fsize" parameter value.
SQL2419N The target disk “disk” has become full.
August 21, 2009
SQL2419N The target disk “disk” has become full.
Explanation:
During the processing of a database utility, the target disk became full. The utility has stopped and the target is deleted.
User Response:
Ensure enough disk space is available for the utility or direct the target to other media, such as tape.
On unix-based systems, this disk full condition may be due to exceeding the maximum file size allowed for the current userid. Use the chuser command to update fsize. A reboot may be necessary.
On non unix-based systems, this disk full condition may be due to exceeding the maximum file size allowed for the operating system. Direct the target to other media, such as tape, or use multiple targets. -
How to create procedure having delete statement with between function?
I am very new in SQL Development, I want to create a procedure having two date variable start and end and these two variable i want to use in procedure body to delete data from a specific table between two date duration.
Please guide
Thanks,create procedure some_proc (start_date date, end_date date)
as
begin
delete from your_table
where your_date_column between start_date and end_date;
end some_proc;
/ -
Error in UPDATE statement with SET and JOIN
Hi
UPDATE lms_assessment_student QS JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1;
The above statement when executing is showing ORA-00971: missing SET keyword. so i changed it to
UPDATE lms_assessment_student QS SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1 JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id ;
and it showing ORA-00933: SQL command not properly ended.So can anyone help me in solving this problem
Thanking you in advance
DinnyHi ,
So many errors
YOUR QUERY :
UPDATE lms_assessment_student QS SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1 JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id ;
and it showing ORA-00933: SQL command not properly ended.So can anyone help me in solving this problem
first thing u want to update qa and u write update QS ??
Second y do u want to join??? just put the condition
SOLUTION
UPDATE lms_assessment_student_ans
SET lms_assessment_student_ans.Mark = 1,
lms_assessment_student_ans.Comment_Field = 1
WHERE lms_assessment_student.pk_Assessment_Stud_Id = 1
AND lms_assessment_student.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id
Hope it works for u..
Bhavesh -
I updated our two IPhone 5s and our IPAD. Our IPAD did not have a pass code and now it does. I tried my wife's and my codes and now our IPAD is disabled. How do I enable our IPAD?
iOS 7 prompts you to create a passcode after updating. You can skip this step but the option is not prominently displayed. It would have looked like this:
If you can't remember what you entered then you will need to restore.
Hopefully you have a backup.
Forgotten Passcode or device disabled after entering wrong passcode -
Backup failure with error code sqlcode: -2419 with DB2 and AIX
Hi,
I have scheduled an online backup for PRD into tape drive and it failed and gave an error mesage
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
B D 20070603230002001 N T S0013124.LOG
Contains 39 tablespace(s):
00001 SYSCATSPACE
00002 PSAPEL31GI
00003 PSAPES31GI
00004 PSAPDDICD
00005 PSAPPOOLI
00006 PSAPUSER1I
00007 PSAPCLUD
00008 PSAPSOURCED
00009 PSAPBTABI
00010 PSAPLOADI
00011 PSAPCLUI
00012 PSAPDOCUI
00013 PSAPSTABD
00014 PSAPPROTI
00015 PSAPBTABD
00016 PSAPPROTD
00017 PSAPLOADD
00018 PSAPSOURCEI
00019 PSAPUSER1D
00020 PSAPSTABI
00021 PSAPDOCUD
00022 PSAPPOOLD
00023 PSAPDDICI
00024 PSAPES46BD
00025 PSAPES46BI
00026 PSAPEL46BD
00027 PSAPEL46BI
00028 SYSTOOLSPACE
00029 PSAPDIMD
00030 PSAPDIMI
00031 PSAPODSD
00032 PSAPODSI
00033 PSAPFACTD
00034 PSAPFACTI
00035 PSAPPEL640D
00036 PSAPES640D
00037 PSAPEL640D
00038 ZSAPBTABD
00039 ZSAPBTABI
Comment: DB2 BACKUP PRD ONLINE
Start Time: 20070603230002
End Time: 20070604050110
Status: A
EID: 40823 Location: /dev/rmt1
SQLCA Information
sqlcaid : SQLCA sqlcabc: 136 sqlcode: -2419 sqlerrml: 9
sqlerrmc: /dev/rmt1
sqlerrp : sqlubMWR
sqlerrd : (1) 0 (2) 0 (3) 0
(4) 0 (5) 0 (6) 0
sqlwarn : (1) (2) (3) (4) (5) (6)
(7) (8) (9) (10) (11)
sqlstate:
can i know what is thisHello,
that's what db2 ? tray to say:
db2 '? sql2419'
SQL2419N The target disk "" has become full.
Explanation:
During the processing of a database utility, the target disk
became full. The utility has stopped and the target is
deleted.
User Response:
Ensure enough disk space is available for the utility or direct
the target to other media, such as tape.
On unix-based systems, this disk full condition may be due to
exceeding the maximum file size allowed for the current userid.
Use the chuser command to update fsize. A reboot may be
necessary.
On non unix-based systems, this disk full condition may be due
to exceeding the maximum file size allowed for the operating
system. Direct the target to other media, such as tape, or use
multiple targets.
I hope this is helpful for you.
Best regards,
Joachim Müller
Maybe you are looking for
-
Connecting a 2nd laptop to wireless router
Hi, Everyone - I have my Mac desktop connected to a WRT54GS wireless router, as well as a Dell laptop connected. All is working fine up till now... Now I'm trying to connect a 2nd Dell laptop but can't get it to connect! It detects the network, but w
-
Vendor Master IDOC - Email address
HI, Requirement is to include email id in outbound vendor master IDOC CREMAS, IDOC only have address number :-( Any pointers how it can be achieved? preferably without coding Also how can I include email address in the change pointers as well (BD52)?
-
Hi While cancelling GR I am getting this error mesg"Check table YEBEFU_CR: entry 10 S91978 00002 does not exist" What could be the reason. Regards, Rad
-
How was this done? Fullscreen mode?
How did they do the fullscreen mode? http://www.sasokos.com Thanks a lot!
-
Loading Measuremen​t Files through a SubVI
Hello! Please forgive me if I sound inexperienced or naive, I am still fairly new to LABVIEW. Hopefully this is an easy question for you experts... I am attempting to make a subVI that loads data and sets conditions for the main VI. I have a subVI th