sql

Inserting multiple rows into Oracle

In the discussion about multiple row insert into the Oracle two approaches were demonstrated: First: insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE) select 8000,0,'Multi 8000',1 from dual union all select 8001,0,'Multi 8001',1 from dual Second: INSERT ALL INTO t (col1, col2, col3) VALUES ('val1_1', 'val1_2', ...

How do you model custom attributes of entities?

Let's say we're having an application which should be able to store all kind of products. Each product has at least an ID and a Name but all other attributes can be defined by the user himself. E.g. He could create a productgroup Ipods which would contain attributes capacity and generation E.g. He could create a productgroup TShirts wi...

Hibernate using an instance of javax.sql.DataSource

Is it possible to configure Hibernate to use a javax.sql.DataSource instance? My application already has an instance of javax.sql.DataSource and I'd rather not re-configure the database url, user, password, driver etc just for hibernate. ...

SQL: Calculating system load statistics

I have a table like this that stores messages coming through a system: Message ------- ID (bigint) CreateDate (datetime) Data (varchar(255)) I've been asked to calculate the messages saved per second at peak load. The only data I really have to work with is the CreateDate. The load on the system is not constant, there are times when...

MERGE INTO insertion order

I have a statement that looks something like this: MERGE INTO someTable st USING ( SELECT id,field1,field2,etc FROM otherTable ) ot on st.field1=ot.field1 WHEN NOT MATCHED THEN INSERT (field1,field2,etc) VALUES (ot.field1,ot.field2,ot.etc) where otherTable has an autoincrementing id field. I would like the insertion into ...

How can I select only one record per “person”, per date with an inner join in an MS Access query?

I need to pull data from two tables: Neptune_FN_Analysis and Neptune_prem There will be 3 fields called readings_miu_id (comparable to a persons name or item #), ReadDate, ReadTime (all of which are in Neptune_FN_Analysis). Some readings_miu_ids have multiple ReadTimes for multiple days but I only want to pull the "last time" entered per...

Something really confusing about how roles and membership tables establish a relationship

Hello, I know how to create users and assign them to roles etc, but when I tried to dig a bit deeper into how roles and membership tables are able to establish a relationship between each other, I got totally lost ( BTW – I do know how foreign/primary keys work ;) ) BTW - I've created tables in databases using aspnet_sqlreg wizard ...

SQL SELECT WHERE Trouble any ideas helpful

I have two tables parent and child (related as such on PK/FK GUID) Child has a Timestamp (the record creation date/time). What I want to do is get only the most recent child record AND the parent record, FOR EACH parent record. SELECT dbo_Parents.ParentName, dbo_ChildEntry.CountPropertys, dbo_ChildEntry.DateTimeStamp FR...

Why does running this query with EXECUTE IMMEDIATE cause it to fail?

I am writing a PL/SQL procedure that needs to to dynamically generate some queries, one of which involves creating a temporary table using results from a query taken as a parameter. CREATE OR REPLACE PROCEDURE sqlout(query IN VARCHAR2) IS BEGIN EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tmp_tab AS (' || query || ');'; END; It c...

Selecting a group with the same value but with one exception

Hi, I have a table with a foreign key, status, code I would like to select the groups with the same foreign key with one record having a code of 001 and status of 'incomplete' and all the rest HAS to have a status of 'completed' id foreignkey code status ------------------------------------------...

Reasons for not using an ORM

Duplicate: Are there good reasons not to use an ORM? We have all heard the reasons for using an orm. What are your reasons for NOT using an ORM? I am an ORM believer, but as a consultant I find that ORM usage is actually very low -- which is strange to me. Many shops refuse to use them, and actively tell their employees not to...

Hibernate NHibernate - Native SQL

Trying to delete an unmapped class/record via the NHibernate sql api. But can't seem to get it working. Does anything look wrong with this? session = NHibernateHelper.GetCurrentSession(); tx = session.BeginTransaction(); using (tx) { session.CreateSQLQuery("DELETE FROM tb_category WHERE parentID = :p...

SQL Server : Creating an index on a table variable

Can you create a index on a table variable in SQL Server 2000? i.e. DECLARE @TEMPTABLE TABLE ( [ID] [int] NOT NULL PRIMARY KEY ,[Name] [nvarchar] (255) COLLATE DATABASE_DEFAULT NULL ) Can I create a index on Name? ...

Modify xml element name in SQL Server

I want to change element name with following statement: SET @myDoc.modify('replace value of (/CustomerInfo)[1] with "Customer"') from <CustomerInfo>     <ID>1</ID> </CustomerInfo> to <Customer>     <ID>1</ID> </Customer> But failed. So how can i change it just in sql ? ...

How do I execute a stored procedure once for each row returned by query?

I have a stored procedure that alters user data in a certain way. I pass it user_id and it does it's thing. I want to run a query on a table and then for each user_id I find run the stored procedure once on that user_id How would I write query for this? SQL SERVER ...

What happened with SQL English query?

SQL Server 2000 was deployed with English Query. At that time, I was young and new to SQL so I skipped that chapter. Now after years, there is again an idea of making a logical program which can understand simple user questions. Is there any alternative to that? Where is English Query now? Best regards, Admir ...

Oracle Form Builder: Switching between tabs in a form

Hi guys, i am building a form in oracle forms builder i have a tabbed canvas i need to know how to swap to the next tab when a button is pressed so what do i program into the next-tab button?? ...

How do i rename the table name using SQL query?

I Used the following syntax but I couldn't find the rename keyword in SQL server 2005. Alter table Stu_Table rename to Stu_Table_10 Please help me in renaming the table name using a query statement. ...

how to get top ten result in sql?

This delow query give me some error: declare @date1 nvarchar(100) , @date2 nvarchar(100) select @date1='2009-04-20', @date2='2009-05-20' select top 10 t.VisitingCount , t.Page from ( select Count(Page) as VisitingCount,Page from scr_SecuristLog where Date between @date1 and @date2 ...

Select datetime prints wrong date

When I select some data rows from mssql2005 database and bind them to datagrid, dates selected from db are invalid. For example in db I have date in form: 2009-05-10 00:00:00.000 but when it is displayed in data grid it looks like this: 5/9/2009 10:00:00 PM So it shows 2 hours earlier then saved in db. 05 - it is month :-) What a...