Is there any better way of writing this query??
I have a query on insert which looks like this,
INSERT INTO TEMP( I1,I2)
SELECT TI1 FROM CLIENT1
WHERE R_CD ='PR' OR 'SR',
SELECT TI2 FROM CLIENT2
WHERE R_CD = 'MN' OR 'OP
There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by [email protected]:
I have a query on insert which looks like this,
INSERT INTO TEMP( I1,I2)
SELECT TI1 FROM CLIENT1
WHERE R_CD ='PR' OR 'SR',
SELECT TI2 FROM CLIENT2
WHERE R_CD = 'MN' OR 'OP
There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.<HR></BLOCKQUOTE>
A possible solution,
INSERT INTO TEMP( I1,I2)
SELECT C1.TI1, C2.TI2
FROM CLIENT1 C1, CLIENT2 C2
WHERE (C1.R_CD = 'PR' OR C1.R_CD ='SR') AND
(C2.R_CD = 'MN' OR C2.R_CD = 'OP')
null
Similar Messages
-
Is there any better way for updating table other than this?
Hi all, I need to update a row in the table that require me to search for it first (the table will have more than hundred thousands of row). Now, I am using a LOV that will return the primary key of the row and put that primary key to DEFAULT_WHERE property in the block and execute query command to fetch the row that need updating. This works fine except that it require 2-query-trip per update (the lov and the execute_query). Is there any better way to doing this? This update is the main objective for my application and I need to use the most effective way to do it since we need to update many records per hour.
Thanks Rama, I will try your method. Others, how to query row instead of primary key? I thought that querying primary key is faster due to the index?
BTW, what people do if you need to update a table using Form? I have been using the LOV then execute query since I first developing form. But I am building a bigger database recently that I start worrying about multiple query trip to dbms.
FYI my table will have up to million rows on it. Each row will be very active (updated) within 1-2 weeks after it creation. After that it will exist for records purposes only (select only). The active rows are probably less than 1% of all the rows. -
How to create a function with dynamic sql or any better way to achieve this?
Hello,
I have created below SQL query which works fine however when scalar function created ,it
throws an error "Only functions and extended stored procedures can be executed from within a
function.". In below code First cursor reads all client database names and second cursor
reads client locations.
DECLARE @clientLocation nvarchar(100),@locationClientPath nvarchar(Max);
DECLARE @ItemID int;
SET @locationClientPath = char(0);
SET @ItemID = 67480;
--building dynamic sql to replace database name at runtime
DECLARE @strSQL nvarchar(Max);
DECLARE @DatabaseName nvarchar(100);
DECLARE @localClientPath nvarchar(MAX) ;
Declare databaselist_cursor Cursor for select [DBName] from [DataBase].[dbo].
[tblOrganization]
OPEN databaselist_cursor
FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Processing DATABASE: ' + @DatabaseName;
SET @strSQL = 'DECLARE organizationlist_cursor CURSOR
FOR SELECT '+ @DatabaseName +'.[dbo].[usGetLocationPathByRID]
([LocationRID])
FROM '+ @DatabaseName +'.[dbo].[tblItemLocationDetailOrg] where
ItemId = '+ cast(@ItemID as nvarchar(20)) ;
EXEC sp_executesql @strSQL;
-- Open the cursor
OPEN organizationlist_cursor
SET @localClientPath = '';
-- go through each Location path and return the
FETCH NEXT FROM organizationlist_cursor into @clientLocation
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @localClientPath = @clientLocation;
SELECT @locationClientPath =
@locationClientPath + @clientLocation + ','
FETCH NEXT FROM organizationlist_cursor INTO
@clientLocation
END
PRINT 'current databse client location'+ @localClientPath;
-- Close the Cursor
CLOSE organizationlist_cursor;
DEALLOCATE organizationlist_cursor;
FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
END
CLOSE databaselist_cursor;
DEALLOCATE databaselist_cursor;
-- Trim the last comma from the string
SELECT @locationClientPath = SUBSTRING(@locationClientPath,1,LEN(@locationClientPath)- 1);
PRINT @locationClientPath;
I would like to create above query in function so that return value would be used in
another query select statement and I am using SQL 2005.
I would like to know if there is a way to make this work as a function or any better way
to achieve this?
Thanks,This very simple: We cannot use dynamic SQL from used-defined functions written in T-SQL. This is because you are not permitted do anything in a UDF that could change the database state (as the UDF may be invoked as part of a query). Since you can
do anything from dynamic SQL, including updates, it is obvious why dynamic SQL is not permitted as per the microsoft..
In SQL 2005 and later, we could implement your function as a CLR function. Recall that all data access from the CLR is dynamic SQL. (here you are safe-guarded, so that if you perform an update operation from your function, you will get caught.) A word of warning
though: data access from scalar UDFs can often give performance problems and its not recommended too..
Raju Rasagounder Sr MSSQL DBA
Hi Raju,
Can you help me writing CLR for my above function? I am newbie to SQL CLR programming.
Thanks in advance!
Satya
-
I am having trouble transferring files from an old MacBook (2007) to a MacBook Air over a wireless network. The connection was interrupted and the time was over 24 hours. Is there a better way to do this? I'm using Migration assistant. The lack of an ethernet port on MacBook air does not help.
William ..
Alternative data transfer methods suggested here > OS X: How to migrate data from another Mac using Mavericks -
My ipad2 freezes when i try to delete a email that has a 78mb pdf file attatched. Is there any other way to delete this file other than the email program?
If it's not MobileMe, use Safari to access the server directly and delet from there. If it is MobileMe, do the same thing but from your computer as the iPad Safari won't connect to MobileMe mail.
-
why cant i update my ios 4.2.1 to 4.3 on my iphone 3g? is there any possible way to do this?
Because the iPhone 3G isn't capable of running iOS 4.3 or newer.
(76029) -
How to find out whether my Iphone 3Gs (OS version 3.1.3) is officlially unlocked ( factory unlocked ) or "made" unlocked ? Can I upgrade its current OS 3.1.3 to OS 5 even if my phone is not officlially unlocked ? how to up grade its OS ? what are there any better ways to do it ?
Thanks,
PRANAJDepends wher you obtained the iPhone from and it's original supplier
If the iPhone is an authorised unlock ( approved by the carrier) or was
purchased from Apple as an unlocked iPhone updating the iOS
will have no effect on the iPhone and it's lock status
HOWEVER if the software has been tampered with to remove the lock,
updating the iOs will lock the iPhone back to the original carrier who holds the lock
To find out the status of your iPhone you could call Apple support
and they may tell you if the iPhone is locked or not and if it is which carrier -
Is there any better way to test an agent?
Every time when I changes some code in the agent, I have to restart the domain to load the new class file. I tried the reload the agent from the Oracle Enterprise Manager, but it is not working. The old agent is still going on. It gives me many troubles since I can't start the SMB server from Window 2000 terminal console. I have to go to the computer room to start SMB natively. Is there any better way to test an agent or start the SMB server in the Window 2000 terminal console?
Your help will be greatly appreciated!Jailcorder requires a jail broken iDevice to work. While it is not illegal to jail brake your iPhone in the US it is illegal to jail break an iPad.
If you do that you will not be able to use these board for help as the discussion of anything relating to a jail broken iDevice is against the TOU and the hosts will remove your posts
In addition looking tha Jailcorder it seems it has not kept up with Apple. It doesn;t work Xcode 5 and IOS 7.
On final thing to keep in mind a jail broken device behaves differently then one that is non jail broken. So even of you test with Jailcode you will still need to go through testing with a non jail broken device before submitting.
All in all if you are serious about developing for IOS it would seem the better course is to get the Developer account now.
regards -
i was stollen and i used the "Remote Wipe" but i didn't know that it won't be able to locate it anymore. It still hasn't wiped it, as it has not been online yet. Is there any possible way to undo this?
First of all i had already blocked it by icloud programm and then after that i received an email of confirmation that it was already blocked. Then i entered in the iCloud programm and saw that the thief it was disconected to not be localized. Do you know that even i had used the Remote Wipe it will work? Because the thief had before the blocked of the phone disconect to not be localized.
-
I allocated too much space on the Windows side when using bootcamp and want to take some space back for the Mac side is there any easy way to do this?
Purchase and use Paragon Camp Tune
-
Is there a better way to do this projection/aggregate query?
Hi,
Summary:
Can anyone offer advice on how best to use JDO to perform
projection/aggregate queries? Is there a better way of doing what is
described below?
Details:
The web application I'm developing includes a GUI for ad-hoc reports on
JDO's. Unlike 3rd party tools that go straight to the database we can
implement business rules that restrict access to objects (by adding extra
predicates) and provide extra calculated fields (by adding extra get methods
to our JDO's - no expression language yet). We're pleased with the results
so far.
Now I want to make it produce reports with aggregates and projections
without instantiating JDO instances. Here is an example of the sort of thing
I want it to be capable of doing:
Each asset has one associated t.description and zero or one associated
d.description.
For every distinct combination of t.description and d.description (skip
those for which there are no assets)
calculate some aggregates over all the assets with these values.
and here it is in SQL:
select t.description type, d.description description, count(*) count,
sum(a.purch_price) sumPurchPrice
from assets a
left outer join asset_descriptions d
on a.adesc_no = d.adesc_no,
asset_types t
where a.atype_no = t.atype_no
group by t.description, d.description
order by t.description, d.description
it takes <100ms to produce 5300 rows from 83000 assets.
The nearest I have managed with JDO is (pseodo code):
perform projection query to get t.description, d.description for every asset
loop on results
if this is first time we've had this combination of t.description,
d.description
perform aggregate query to get aggregates for this combination
The java code is below. It takes about 16000ms (with debug/trace logging
off, c.f. 100ms for SQL).
If the inner query is commented out it takes about 1600ms (so the inner
query is responsible for 9/10ths of the elapsed time).
Timings exclude startup overheads like PersistenceManagerFactory creation
and checking the meta data against the database (by looping 5 times and
averaging only the last 4) but include PersistenceManager creation (which
happens inside the loop).
It would be too big a job for us to directly generate SQL from our generic
ad-hoc report GUI, so that is not really an option.
KodoQuery q1 = (KodoQuery) pm.newQuery(Asset.class);
q1.setResult(
"assetType.description, assetDescription.description");
q1.setOrdering(
"assetType.description ascending,
assetDescription.description ascending");
KodoQuery q2 = (KodoQuery) pm.newQuery(Asset.class);
q2.setResult("count(purchPrice), sum(purchPrice)");
q2.declareParameters(
"String myAssetType, String myAssetDescription");
q2.setFilter(
"assetType.description == myAssetType &&
assetDescription.description == myAssetDescription");
q2.compile();
Collection results = (Collection) q1.execute();
Set distinct = new HashSet();
for (Iterator i = results.iterator(); i.hasNext();) {
Object[] cols = (Object[]) i.next();
String assetType = (String) cols[0];
String assetDescription = (String) cols[1];
String type_description =
assetDescription != null
? assetType + "~" + assetDescription
: assetType;
if (distinct.add(type_description)) {
Object[] cols2 =
(Object[]) q2.execute(assetType,
assetDescription);
// System.out.println(
// "type "
// + assetType
// + ", description "
// + assetDescription
// + ", count "
// + cols2[0]
// + ", sum "
// + cols2[1]);
q2.closeAll();
q1.closeAll();Neil,
It sounds like the problem that you're running into is that Kodo doesn't
yet support the JDO2 grouping constructs, so you're doing your own
grouping in the Java code. Is that accurate?
We do plan on adding direct grouping support to our aggregate/projection
capabilities in the near future, but as you've noticed, those
capabilities are not there yet.
-Patrick
Neil Bacon wrote:
Hi,
Summary:
Can anyone offer advice on how best to use JDO to perform
projection/aggregate queries? Is there a better way of doing what is
described below?
Details:
The web application I'm developing includes a GUI for ad-hoc reports on
JDO's. Unlike 3rd party tools that go straight to the database we can
implement business rules that restrict access to objects (by adding extra
predicates) and provide extra calculated fields (by adding extra get methods
to our JDO's - no expression language yet). We're pleased with the results
so far.
Now I want to make it produce reports with aggregates and projections
without instantiating JDO instances. Here is an example of the sort of thing
I want it to be capable of doing:
Each asset has one associated t.description and zero or one associated
d.description.
For every distinct combination of t.description and d.description (skip
those for which there are no assets)
calculate some aggregates over all the assets with these values.
and here it is in SQL:
select t.description type, d.description description, count(*) count,
sum(a.purch_price) sumPurchPrice
from assets a
left outer join asset_descriptions d
on a.adesc_no = d.adesc_no,
asset_types t
where a.atype_no = t.atype_no
group by t.description, d.description
order by t.description, d.description
it takes <100ms to produce 5300 rows from 83000 assets.
The nearest I have managed with JDO is (pseodo code):
perform projection query to get t.description, d.description for every asset
loop on results
if this is first time we've had this combination of t.description,
d.description
perform aggregate query to get aggregates for this combination
The java code is below. It takes about 16000ms (with debug/trace logging
off, c.f. 100ms for SQL).
If the inner query is commented out it takes about 1600ms (so the inner
query is responsible for 9/10ths of the elapsed time).
Timings exclude startup overheads like PersistenceManagerFactory creation
and checking the meta data against the database (by looping 5 times and
averaging only the last 4) but include PersistenceManager creation (which
happens inside the loop).
It would be too big a job for us to directly generate SQL from our generic
ad-hoc report GUI, so that is not really an option.
KodoQuery q1 = (KodoQuery) pm.newQuery(Asset.class);
q1.setResult(
"assetType.description, assetDescription.description");
q1.setOrdering(
"assetType.description ascending,
assetDescription.description ascending");
KodoQuery q2 = (KodoQuery) pm.newQuery(Asset.class);
q2.setResult("count(purchPrice), sum(purchPrice)");
q2.declareParameters(
"String myAssetType, String myAssetDescription");
q2.setFilter(
"assetType.description == myAssetType &&
assetDescription.description == myAssetDescription");
q2.compile();
Collection results = (Collection) q1.execute();
Set distinct = new HashSet();
for (Iterator i = results.iterator(); i.hasNext();) {
Object[] cols = (Object[]) i.next();
String assetType = (String) cols[0];
String assetDescription = (String) cols[1];
String type_description =
assetDescription != null
? assetType + "~" + assetDescription
: assetType;
if (distinct.add(type_description)) {
Object[] cols2 =
(Object[]) q2.execute(assetType,
assetDescription);
// System.out.println(
// "type "
// + assetType
// + ", description "
// + assetDescription
// + ", count "
// + cols2[0]
// + ", sum "
// + cols2[1]);
q2.closeAll();
q1.closeAll(); -
Is there a better way to do this? Interactive graphics on a PDF
Hello
Part of a PDF form I am planning requires the user to place several marks on a series of dots.
I have partially achieved this using check boxes and many hidden objects.
http://www.hoodoomayhem.com/example/Example.pdf focus on the small dots in the upper right.
Is there a smarter way to achieve this without using thousands of hidden objects.
I am quite new to scripting and do appreciate any suggestions.
I look forward to some feedback
BonbeketThat update should only be a single statement - not within a loop. The basic structure here should be something like:
update central_printing_staging cps
set sent_for_printing_date = trim(sysdate)
where central_printing_staging_id in (select ...
from <variation of complex query>);
open p_centralprinting_refcursor
for <complex query snipped>;The only question I have is whether the ref cursor is supposed to reflect the updated values or not, or if the two are even related or not - can't tell without seeing the query. -
Is there a better way to do this with Flash?
I am new to Flash but am slowly teaching myself via Lynda.com etc
I have an image that I have added to a website via a content management system and want to make certain areas of that image into links to other sites.
I found this page that does the kind of thing I want to do, but it appears from looking at the source code that the person who has done this has cut the image up into several sections in order to fit it into a table: http://www3.imperial.ac.uk/staffdevelopment/postdocs1/guidance
Is there a better way to achieve the same kind of effect using Flash by making ares of an image into links and keeping the image as a whole?There are ways to keep the image whole and have portions of it linking to different places both in HTML and in Flash. In HTML you can use an image map. In Flash, you can just lay invisible buttons atop the image and use those to link.
-
my aunt got my cousin a new iphone, so she gave me my cousin's old iphone. I reset the the phone she gave me so i can set it up for my own use now. The problem is that i need the account of my cousin in order to activate the phone, the bad news is that her account was hacked. Is there any other way that i can activate this account and put it on my list of devices? So that if i want to reset it, i'll just use my account to activate it.
P.S.
i Do have a proof that this phone was given to me by my aunt and she is the one who bought it for my cousin.Your cousin needs to contact Apple and ask to speak to someone in account security to get the Apple ID back under his/her control.
If your aunt has original proof of purchase for the phone, she can bring that, along with the phone, to an Apple store or call Apple and they may be able to assist.
~Lyssa -
Is there a better way to do this function?
Hi,
I was just wondering if someone can suggest a better way of doing the function I have attached below. Basically, it is counting pulses (falling edges) over a 250ms time period and converting that to speed. There seems to be some cases where it counts lesser pulses for a longer period than 250ms which results in lower speeds, but physically the device doesnt run any slower. Or sometimes speed is higher. This code was written by someone else and I am trying to work it better.
V
P.S. There is an overall master While loop.
I may not be perfect, but I'm all I got!
Attachments:
counter_wait.JPG 87 KBVeeJay wrote:
@ yamaeda what do you mean by coercion dots? Can you explain in simpler terms.? Thanks!
V
coercion dots are those red dots on your arithmatic functions. That means you are dividing data of different types. For instance I32 and U8 would give you a coercion dot. What you will want to do is right click your constants, choose representation->[data type]. Either that, or you can go to the numeric-> conversion pallette (i think) thats where it is and convert numbers using the primitives there.
CLA, LabVIEW Versions 2010-2013
Maybe you are looking for
-
When you create a site column of TaxonomyField type, SharePoint creates a "shadow" hidden field with the same name plus a trailing underscore and number. When you delete the main taxonomy field, SharePoint does NOT delete the shadow field. If you are
-
TNS-12535: TNS:operation timed out on Vista SP1 OS
Hi everyone, I am starting to play with Oracle DB recnetly.. today I have TNS connection failed issue. When I tried to use ODBC to connect Oracle XE DB, I got ORA-12535: TNS:operation timed out. Here is basic info: OS:Vista SP1 Oracle Version:Oracle
-
please help, someone that doesn't have the savay on moving music from an old pc to a new pc. Music will not play message comes up and have to search. also purchased music from iPhone and does not show on my music library on PC. This is very frustra
-
1.How to connect to different databases from sql??? 2.How to view list of different databases through sql??? 3.How to retrive password if you forget of sql??? 4.How to create tablespace ??? 5.How to view the list of Users of a specific database??? 6.
-
N series compatibility in USA & Canada
hi. can somebody to tell me exactly if one of the following N series models as: N80, N73 ME, N95, bought in United Emirates, are full compatible in USA or Canada? I'll do appreciate for any answer. I wanna also to mention: these all models are not lo