SQL 2008, Update using multiple SubQuery
Hello Experts ,
I WANT TO DO THIS UPDATE WITHOUT USING CTE
I have Two Table REGION and AREA
REGION TABLE HAVE VALUE LIKE
Create Table REGIONtbl (REGION varchar(20),SomeArea varchar(20))
Insert into REGIONtbl
select 'REGION1','' union all
select 'REGION2','' union all
select 'REGION3',''
select * from REGION
OTHER table is AREA
Create Table AREAtbl(AREAS varchar(20))
Insert into Areatbl
select 'area1','' union all
select 'area2','' union all
select 'area3',''
I want to upadte AREAs in SomeArea column of Region Table ,
I Need to first create autoincrement column in both Table using Row_Number function and Upadte "SOMEAREA" column with "Areas" column
where ever ROW_Number ID of both the Table match
I tried below but did not work..
UPDATE MASTER
SET MASTER.somearea =ar.areas
FROM
SELECT Row_number() over (order by REGION) RN,
REGION, somearea FROM REGIONtbl
) AS MASTER
SELECT areas, ROW_NUMBER() OVER (ORDER BY areas)RNa
FROM areatbl
)AR
where MASTER.rn=ar.rna
HELP ?
Please 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. You have no idea.
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 want to do this update without using CTE <<
Why? Is that part of a homework assignment?
>> I have Two Tables REGION [sic] and AREA [sic] <<
No, tables are sets so their names plural or collective nouns. Putting “tbl” in a name is called “tibble”, a common design flaw that we laugh at. Look for Phil Factor’s humor column on this.
Here is my guess at what you should have posted in order to do this the way you want to do it.
CREATE SEQUENCE Region_Garbage
AS INTEGER
START WITH 1
INCREMENT BY 1;
CREATE SEQUENCE Area_Garbage
AS INTEGER
START WITH 1
INCREMENT BY 1;
CREATE TABLE Regions
(region_name VARCHAR(20) NOT NULL PRIMARY KEY,
region_seq INTEGER NOT NULL,
area_name VARCHAR(20) DEFAULT '' NOT NULL);
INSERT INTO Regions (region_name, region_seq)
VALUES ('region_name1', NEXT VALUE FOR Region_Garbage);
INSERT INTO Regions (region_name, region_seq)
VALUES ('region_name2', NEXT VALUE FOR Region_Garbage);
INSERT INTO Regions (region_name, region_seq)
VALUES ('region_name3', NEXT VALUE FOR Region_Garbage);
CREATE TABLE Areas
(area_name VARCHAR(20) NOT NULL PRIMARY KEY,
area_seq INTEGER NOT NULL);
INSERT INTO Areas (area_name, area_seq)
VALUES ('area_name1', NEXT VALUE FOR area_Garbage);
INSERT INTO Areas (area_name, area_seq)
VALUES ('area_name2', NEXT VALUE FOR area_Garbage);
INSERT INTO Areas (area_name, area_seq)
VALUES ('area_name3', NEXT VALUE FOR area_Garbage);
CREATE TABLE Areas
(area_name VARCHAR(20) NOT NULL PRIMARY KEY,
area_seq NEXT VALUE FOR Area_Garbage);
>> I want to update area_name column of Regions Table <<
I would fire you for doing this, but here is a stinking kludge.
The term “Master” is from magnetic tape files, not RDBMS! Then to make it worse, you have used the old Sybase UPDATE. FROM.. syntax! It is unpredictable. Use the MERGE:
MERGE INTO Regions AS R
USING Areas AS X
ON X.area_seq = R.region_seq
WHEN MATCHED
THEN UPDATE
SET area_name = X.area_name;
--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
Similar Messages
-
How do I import a SPSS .sav file into SQL 2008 r2 using SSIS
Hi there,
Like the title says, I'm trying to import an SPSS .SAV file into an SQL 2008 R2 database using SSIS.
I've tried a few things, but i cant seem to get it to work properly. I'm hoping there's someone out there who could point me in the right direction.
I've tried the following:
Tried the IBM step by step manual (http://pic.dhe.ibm.com/infocenter/spssdc/v6r0m1/index.jsp?topic=%2Fcom.spss.ddl%2Faccess_odbc.htm)
--Couldnt folow this guide because I didnt have the SPSS MR DM-2 OLE DB Provider.
Tried installing the provider using (http://pic.dhe.ibm.com/infocenter/spssdc/v7r0m0/index.jsp?topic=%2Fcom.spss.ddl%2Fdts_troubleshooting.htm) as a guide to download the provider listed (www-03.ibm.com/software/products/nl/spss-data-model).
--This didnt work, I still could not see the provider listed after install and rebooting the server.
Tried to get the file as CSV (Company couldnt provide it in CSV or another format)
The server is a Windows Server 2008 R2 Enterprise 64-bit, has the Data Collection Data Model installed on it with SQL Server 2008 R2.
If anyone could point me in the right direction they could make my day!
Thanks in advance!
RonnyHi Ronny,
According to your description, you want to import a SPSS .sav file to SQL Server 2008 R2 database. If that is the case, we can achieve this requirement with SPSS or SQL query. For more details, please refer to the following methods:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93346
http://ilovespss.blogspot.com/2007/10/migrating-data-from-spss-to-sql-server.html
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Upgrade MS SQL 2005 platform to MS SQL 2008 - Update the JDBC driver...
Hello to all,
This is the second post that I created reporting this error because in the first one I open this message in group of "SAP on SQL Server" but without any kind of help from community:
My problem is...
I´m planning to do an upgrade of a sap system (SAP ECC 6.0) from SQL Server 2005 to a SQL Server 2008 but I´m facing with a little problem. This system has two stacks - ABAP + JAVA - and because of that the Upgrade Guide to MS SQL Server 2008 describe which are the requirements for this upgrade DB platform, and one of them is this:
"If you use a Java system, you have updated the JDBC driver as described in SAP Note 639702"
... the updated of JDBC driver when we have in system a Java part, like it has in this case! But I´m with a serious problems to find in SAP System Files in Windows 2003 Server the four files that is mentioned in that note 639702. I can´t find it anywhere... in note says:
Depending on the SAP release and the system configuration, the driver files base.jar, util.jar, sqlserver.jar, and spy.jar are available in an installed system at:
(NetWeaver'04, Java:) usrsap<SAP SID>JC<InstanceNumber>j2eejdbc
(NetWeaver'04, ABAP+Java:) usrsap<SAP SID>DVEBMGS<InstanceNumber>j2eejdbc
(NetWeaver 2004s:) usrsap<SAPSID>SYSexe<NUC|UC>Platformmssjdbc
But... still I didn´t find them! I also read other note 1109274 - New JDBC driver for NetWeaver 7.0 and higher but even so I still can´t find it!
Can you help me to find this files on my operation system? I have to update that JDBC... but of course for this task I have to find it first!!!
Best regards,
João Dimas - PortugalHi,
Have you considered the possibility that the directory that was supposed to contain the jdbc drivers has been replaced by a recent kernel upgrade and you never noticed?
Anyway, looking forward, put in a new set of JDBC drivers in the correct location.
Also, with reference to the following point from the first note:
Check your JDBC Driver version before you download it. To do this, unpack the attached check tool SAPCheckVersion in the relevant JDBC directory (refer to the previous paragraph). Then open a command prompt there and execute the following command:
SAPCheckVersion.cmd <server name> <username> <password>
Replace <server name> with the name of the database server, <username> and <password> with the logon data of an SQL user (for example, sa or SAP<SID>DB). If you call SAPCheckVersion.cmd without a parameter, the system displays detailed help. The tool supports both DataDirect and Microsoft drivers.
*The download name tells you which version of the driver you need to download from SAP Service Marketplace.*
Run this SAPCheckVersion and find out which drivers you need to download and then download them and use them.
Regards,
Shitij -
Upgrade MS SQL 2005 platform to MS SQL 2008 - Update the JDBC driver issue
Hello to all,
I´m planning to do an upgrade of a sap system (SAP ECC 6.0) from SQL Server 2005 to an SQL Server 2008 but I´m facing with a little problem. This system has two stacks - ABAP + JAVA - and because of that the Upgrade Guide to MS SQL Server 2008 describe which are the requirements for this upgrade DB platform, and one of them is this:
"If you use a Java system, you have updated the JDBC driver as described in SAP Note 639702"
... the updated of JDBC driver when we have in system a Java part, like it has in this case! But I´m with a serious problems to find in SAP System Files in Windows 2003 Server the four files that is mentioned in that note 639702. I can´t find it anywhere... in note says:
Depending on the SAP release and the system configuration, the driver files base.jar, util.jar, sqlserver.jar, and spy.jar are available in an installed system at:
(NetWeaver'04, Java:) usrsap<SAP SID>JC<InstanceNumber>j2eejdbc
(NetWeaver'04, ABAP+Java:) usrsap<SAP SID>DVEBMGS<InstanceNumber>j2eejdbc
(NetWeaver 2004s:) usrsap<SAPSID>SYSexe<NUC|UC>Platformmssjdbc
But... still I didn´t find them! I also read other note 1109274 - New JDBC driver for NetWeaver 7.0 and higher but even so I still can´t find it!
Can you help me to find this files on my operation system? I have to update that JDBC... but of course for this task I have to find it first!!!
Best regards,
João Dimas - PortugalHello John Feely,
Yeah I already know that you mentioned! In my first post/previous message I mentioned that, I already read the note 639702 and it was there I read that explanation... regarding that creation that you refer in the case of files are not in those directories, so you said that I could download this four files and put in there... but where? and how..? Sorry but that solution seems does not make any sense!
I also look other systems with double stack ABAP + JAVA and I one more time I didn´t see that directories or files that are mentioned in that note!! DAMN!
Any tip?
Kind regards,
João Dimas - Portugal -
SQL Bulk Update using Update query in SQL Table
Hello All,
I want to update data in sql table depends on some condition.
I am getting excel sheet from client and want to change value of field say Status = c.
Client is sending excel sheet with 300 field and want to change value for all 300 records with unique fields (field1 and field2) comming in that excel sheet...
How can i write and update records as Bulk.
Instaed updating one one recors ?
Example ( Update Table_Name Set Status = 'c' Where Field1 = Value from Excel for Field1 and
Field2 = Value from Excel for Field2 )
Same needs to do for 300 records...
Any help will wellcome.
Thanks,
Nilesh....
Thanks and Regards, Nilesh Thakur.you can use OPENROWSET for that
http://www.mssqltips.com/sqlservertip/1540/insert-update-or-delete-data-in-sql-server-from-excel/
Another way is to use SSIS with data flow task having Excel source connecting to excel and using OLEDB command to update rows in table using it. You may also use staging table to get data from excel and later use it inexecute sql task to update your table
to make update set based which would be faster.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to update using multiple languages.
I am using Eclipse and TomCat to a Oracle 10g database. Using SQL developer I can enter multi-language characters into the nvarchar2 columns. My application creates SQL update Strings that look like this:
update CLIENTINCUMBENT set UNITCODE = UNISTR('66'), EMPLOYEECODE = UNISTR('000607'), LASTNAME = 'Ыфтвууз', FIRSTNAME = UNISTR('Ощрфк'), JOBCODE = UNISTR('PM003'), BASESALARY = '108160', BASESALARYCURR = UNISTR('USD'), BONUS = '24000', BONUSELIG = 'Y', BONUSCURR = UNISTR('USD'), TGTBONUSPCT = '25000', SUPERVISOREMPLOYEECODE = UNISTR('USD'), DDE005 = UNISTR('5000'), DDE006 = UNISTR('10'), DDE007 = UNISTR('Right Wing'), DDE008 = UNISTR('M'), DDE009 = UNISTR('PHI'), DDE010 = UNISTR('USC'), DDE011 = UNISTR('001738'), DDE012 = '2000-12-22 00:00:00', DDE013 = '24', DDE014 = UNISTR('Caucasian') where clientdataid = 'A10138453627' and EMPLOYEECODE = '000607'
Note the lastname and firstname columns.
The update succeeds however SQL developer shows garbled characters in the lastname and firstname fields.
Data the I enter in using the DATA view in SQL developer shows correctly in my web app in the different languages.
If I change the lastname to include both english and cyrillic characters the english characters show through but the cyrillic is garbled.
Can someone point me at what I should be looking at?Database is Oracle 10.2g on Windows Server 2003
We do not wish to change the database character set if at all possible.
Session Parameters are:
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
Database Parameters are:
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET WE8MSWIN1252
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 10.2.0.1.0
Thanks
Edited by: user11089978 on May 27, 2010 7:04 AM
Edited by: user11089978 on May 27, 2010 7:10 AM -
SQL 2008 R2 SSRS Security Problems
Hello,
We have SSRS running on SQL 2008 R2, using a Windows 2008 R2 Standard Server. When we setup Systems users and also roles such as Browser all that goes through. The issue is, the security does not take effect on the system.
For example <domainuser>\<domainuser> can login to the site and traverse ANY folders, even ones that have folder security set, not inheritening permissions. I've came to realize it seems the Windows Group "Users" applies to who can
get into the server. If we do not have domain users or specific logins in the Windows group you just keep getting a popup for login going to the main SSRS home.
I do not the behavior concerning windows group by design but at any rate adding all domain users we then perceive the folder and site settings apply to folders and report access on the Report manager. It does not simply work. Any users can get into
the admin folder (Which has only 3-4 people with access) and run anything. It is as if the SSRS permissions simply do not work. I've tried using a server account and also Network Service (Which it is set to now).
Has anyone ran into this issue and have any ideas how to resolve it? I understand the BROWSER role has access to "View Folders" but I see no granular other than folder and item permissions being set to not allow specific folders to be accessed.
I appreciate your time,
KTHi KT,
Per my understanding that you have set the security in the report server but the some of the user still get some extra permission, right?
Generally, Reporting Services uses role-based security to grant user access to a report server, and there are two types of roles:
Item-level roles and System-level roles.
By default, Reporting Services has assigned both System Administrator roles (System-level) and the Content Manager role (Item-level) to the BUILTIN\Administrators group. So, the user that is in the local administrators group will
perform the role as ”Content Manager” without extra settings, you can check if the users who have extra permissions was in this group,if the domain user in this group, please try to remove it and add it in the Local Users and Groups other
then Administrators group :
You have menioned that the user shouldn't have permission to the Admin folder but now they have access.
Please check the security of the admin folder to make sure the users were not in the list of the groups and users as below:
If the issue still exists, please check all the folder one by one to make sure this is not any inheried problem and re-set the security.
Similar thread for your reference:
How to remove the DELETE item from the Running report context
list box
If you still have any question, please feel free to ask.
Regards
Vicky Liu
Vicky Liu
TechNet Community Support -
Mutiple transcation update using bdc
Dear Gurus
I have two questions .
1. Can we update two transaction code using CALL TRANSACTION method in BDC?
through searching in the forum i found that it not possible to update multiple transaction using CALL TRANSACTION method to update two t code simultaneously i have to use BDC session method , because CALL TRANSACTION method uses Asynchronous method for update data.
2.Suppose I am updating multiple transaction code using session method at first i create sales order using va01 when sales order is created how i collect this sales order no to use in the second t code in session method.
Thanks in advance.
Chitta Ranjanmahato123 wrote:
through searching in the forum i found that it not possible to update multiple transaction using CALL TRANSACTION method to update two t code simultaneously i have to use BDC session method , because CALL TRANSACTION method uses Asynchronous method for update data.
Don't know where you got this, but it's definitely possible to update using multiple transactions sequentially.
Rob -
Is it possible to use multiple proxies simulatneously?
I have access to four different proxy servers within my college. (Squid I think)
Each proxy has limitations on the number of simultaneous GET requests (4 I think. When I set anything higher
in Firefox images don't load, etc..) and allows only http and https traffic. I was thinking if it was possible to use
all/at least more than one proxy at a time to improve speeds.
Does wget/aria2c have this capability? To download segments of a file from different proxies simultaneously instead of just one?
I'd seen the manpages but as far as I can tell they use only one proxy server at a time (usually through environment variables)
In fact I'd be happy if I were able to get good download speeds for pacman updates using multiple proxies.
I've heard of network interface bonding but it looks like a lot of trouble to set it up (kernel recompilation! )
Is http://www.cyberciti.biz/howto/question … -howto.php the way or is there any other?
Just thought I'd know all possibilities before compiling kernels and stuff..I don't know if aria2 can use multiple proxies simultaneously, but if you want to download packages quickly through multiple proxies, you could do the following in a script:
generate a metalink for your packages using powerpill
split the metalink into separate metalinks with roughly the same download volume in each one
launch separate instances of aria2c for each metalink, each set to a different proxy
If you try this, don't forget to change the connection settings in the powerpill configuration file (or when you split the metalink) to avoid more than 4 connections per proxy. -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
SQL 2008 R2 Best Practices for Updating Statistics for a 1.5 TB VLDB
We currently have a ~1.5 TB VLDB (SQL 2008 R2) that services both OLTP and DSS workloads pretty much on a 24x7x365 basis. For many years we have been updating statistics (full scan- 100% sample size) for this VLDB once a week on the weekend, which
is currently taking up to 30 hours to complete.
Somewhat recently we have been experiencing intermitent issues while statistics are being updated, which I doubt is just a coincidence. I'd like to understand exactly why the process of updating statistics can cause these issues (timeouts/errors). My theory
is that the optimizer is forced to choose an inferior execution plan while the needed statistics are in "limbo" (stuck between the "old" and the "new"), but that is again just a theory. I'm somewhat surprised that the "old" statistics couldn't continue to
get used while the new/current statistics are being generated (like the process for rebuilding indexes online), but I don't know all the facts behind this mechanism yet so that may not even apply here.
I understand that we have the option of reducing the sample percentage/size for updating statistics, which is currently set at 100% (full scan). Reducing the sample percentage/size for updating statistics will reduce the total processing time, but
it's also my understanding that doing so will leave the optimizer with less than optimal statistics for choosing the best execution plans. This seems to be a classic case of not being able to have one’s cake and eat it too.
So in a nutshell I'm looking to fully understand why the process of updating statistics can cause access issues and I'm also looking for best practices in general for updating statistics of such a VLDB. Thanks in advance.
Bill ThackerI'm with you. Yikes is exactly right with regard to suspending all index optimizations for so long. I'll probably start a separate forum thread about that in the near future, but for now lets stick to the best practices for updating statistics.
I'm a little disappointed that multiple people haven't already chimed in about this and offered up some viable solutions. Like I said previously, I can't be the first person in need of such a thing. This database has 552 tables with a whole lot more statistics
objects than that associated with those tables. The metadata has to be there for determining which statistics objects can go (not utilized much if at all so delete them- also produce an actual script to delete the useless ones identified) and what
the proper sample percentage/size should be for updating the remaining, utilized statistics (again, also produce a script that can be used for executing the appropriate update statistics commands for each table based on cardinality).
The above solution would be much more ideal IMO than just issuing a single update statistics command that samples the same percentage/size for every table (e.g. 10%). That's what we're doing today at 100% (full scan).
Come on SQL Server Community. Show me some love :)
Bill Thacker -
How can I use multiple row insert or update into DB in JSP?
Hi all,
pls help for my question.
"How can I use multiple rows insert or update into DB in JSP?"
I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
With thanks,That isn't true. Different SQL databases have
different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
and there are also a lot of different ways of talking to
SQL databases that are possible in JSP, from using
plain old java.sql.* in scriptlets to using the
jstlsql taglib. I've done maintenance on both, and
they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
Well, sure. As long as you only want to update rows
with the same value in column 2. I had the impression
he wanted to update a whole table. If he only meant
update all rows with the same value in a given column
with the same value, that's trivial. All updates do
that. But as far as I know there's know way to update
more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
Unless you're using MySQL, for instance. I only have
experience with MySQL and M$ SQL Server, so I don't
know what PostgreSQL, Oracle, Sybase, DB2 and all the
rest are capable of, but I know for sure that MySQL
can insert multiple rows while SQL Server can't (or at
least I've never seen the syntax for doing it if it
does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
Don't assume that all SQL databases are the same.
They're not, and it can really screw you up badly if
you assume you can deploy a project you've developed
with one database in an environment where you have to
use a different one. Even different versions of the
same database can have huge differences. I recommend
you get a copy of the O'Reilly book, SQL in a
Nutshell. It covers the most common DBMSes and does a
good job of pointing out the differences.Yes, I understand that.
It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing. -
Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT
Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT. Below SQL is an example of what I am trying to do - In this case instead of using JOIN, can I have three pivot_for_clauses in the same sql?
SQL:
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
FROM (SELECT company_id,action_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id) IN ((1) as num_logins,(2) as num_logouts,(61) as
num_logins_from_mobile_device,(16) as num_pref_changed,....)) P1
JOIN
(SELECT company_id,action_type_id,tx_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice, (4,4) AS
edit_invoice,(3,3) as num_checks,(3,47) as num_paychecks,(3,7) as num_recvd_payments,(3,9) as num_bills,
(3,35) as num_estimates,(3,46) as num_purchase_orders)) P2
on P1.company_id=P2.company_id
JOIN
(SELECT company_id,action_type_id,list_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,(3,1) as
num_accounts,(3,4) as num_employees,(3,6) as num_customers,(3,14) as num_memorized_reports)) P3
on P2.company_id=P3.company_id
left outer JOIN
(SELECT company_id,create_date,count(*) as num_logos
FROM qbo.companylogos_1 group by company_id,create_date having trunc(create_date)=trunc(sysdate)-1) P4
on P3.company_id=P4.company_id
ORDER BY P1.company_id) source
ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))WHEN MATCHED THEN
UPDATE SET dest.num_items = source.num_items where 1=2
WHEN NOT MATCHED THEN
INSERT (dest.company_id,.....) values (source.company_id,.....);Maybe
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
FROM (select *
from (SELECT company_id,action_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id) IN ((1) as num_logins,
(2) as num_logouts,(61) as num_logins_from_mobile_device,
(16) as num_pref_changed,....
) P1
JOIN
(select *
from (SELECT company_id,action_type_id,tx_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice,
(4,4) AS edit_invoice,
(3,3) as num_checks,
(3,47) as num_paychecks,
(3,7) as num_recvd_payments,
(3,9) as num_bills,
(3,35) as num_estimates,(3,46) as num_purchase_orders
) P2
on P1.company_id = P2.company_id
JOIN
(select *
from (SELECT company_id,action_type_id,list_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,
(3,1) as num_accounts,
(3,4) as num_employees,
(3,6) as num_customers,
(3,14) as num_memorized_reports
) P3
on P2.company_id = P3.company_id
left outer JOIN
(SELECT company_id,create_date,count(*) as num_logos
FROM qbo.companylogos_1
group by company_id,create_date
having trunc(create_date) = trunc(sysdate)-1
) P4
on P3.company_id = P4.company_id
ORDER BY P1.company_id
) source
ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))
WHEN MATCHED
THEN UPDATE SET dest.num_items = source.num_items where 1 = 2
WHEN NOT MATCHED
THEN INSERT (dest.company_id,.....)
values (source.company_id,.....)Did you try it ?
Regards
Etbin -
Hi,
I have a windows 2008 R2 Enterprise servers with standalone MS-SQL 2008 R2 named instance. The server is having two networks, once production and the second for backup. The server FQDN is resolving to the production IP. The backup NIC
DNS dynamic update is disabled and an "A" record is registered with the dns. While trying to connect to the instance using the management studio:
Successfuly able to connect using the instance name, the production hostname, production IP and backup IP.
but while trying to connect to the insance using the backup hostname getting the below error:
"Login failed. The login is an untrusted domain and cannot be used with windows authentication. (Microsoft SQL server, Error: 18452) "
This is required for the backup tool to get connected using the backup FQDN of the server.
Should I need to create a host name alias, request you to kindly assist me with the best recommedation to fix this.
http://blogs.msdn.com/b/dbrowne/archive/2012/05/21/how-to-add-a-hostname-alias-for-a-sql-server-instance.aspxHi,
It might be a kerberos issue. Check that there are valid SPN's registered using the setspn utility - http://technet.microsoft.com/en-us/library/cc731241.aspx
Thanks, Andrew
My blog... -
MS-SQL Server 2008 Update Statistics
Hi,
We have SAP running on MS-SQL 2008. Can we use the command 'sp_updatestats' to update stats on all tables in the schema or is there any option we can schedule a job from DBACOCKPIT?
Thanks,
KrisYes, you can use sp_updatestats as described here [MS173804|http://msdn.microsoft.com/en-us/library/ms173804.aspx] with MS SQL Server 2008.
I do not believe you can create the job from DBACOCKPIT, however.
Maybe you are looking for
-
I have read the posts about caching initial context lookups and have implemented the solution and seen some benefits. I am dealing with a third party application that I cannot change. When I put my InitialContextFactory in the architecture I also log
-
i am trying to rename files in a folder nine files name are taken from the text file dnine.txt were for every occurance of a number in the filename i wrote this code it reaches the condition as marked bold but it isnt renaming the files plzz help imp
-
Reload Software: 552 Error
I got a blackberry tour for about 4 months now and absolutely love it... until it started getting this 552 error. Last time it happend, i was on a trip and i ended up not having a functional phone for an entire weekend since i had no access to a wind
-
Executing Proxy in Background Mode
Hi All Is it possible to execute the proxy in background mode ?? This is for a File->XI->ABAP Proxy interface..the message size is more than 30MB and is getting timed out in the inbound queue of the receiver (abap prxy)after 10mins. This is bcoz the
-
Need a select statement to trim a single value out of a column
I have a column which can and does contain single and multiple values. For instance, there could be a single value, value, or it could look like this value, value, with there being a comma and a space between the two values. I need a select statement