sql

Convert string id of column to int autoincrement

Hi, I have table Cars Id nvarchar(25) PK Name nvarchar(max) And there is some records. Id Name CodeXYZ Namezxc CodeQAZ Nameasd CodeEDC Nameqwe I want to convert Id column to int autoincrement: Id Name 1 Namezxc 2 Nameasd 3 Nameqwe but I have no idea how to make it :/ Could you help me ? ...

Combine NamedQuery and Criteria in Hibernate

I use Hibernate in a storefinder application. For the proximity search in SQL I use the haversine formula. Because this is a bit messy SQL I created a named SQL query in my .hbm.xml File for this. SELECT location.*, ( 3959 * acos( cos( radians(7.4481481) ) * cos( radians( X(location.coordinates) ) ) * cos( radians( ...

how do i combine two selects from one table where one has a GROUP BY and the other has a DISTINCT

Both of these work individually SELECT PONumber, count(RequestNumber) as "InNumOfRequests", sum(Amount) as "SumofAmounts" FROM tableView GROUP BY PONumber SELECT DISTINCT PONumber, (10 * ceiling((DATEDIFF(day,POApprovedDate,GETDATE()))/10)) AS "BINofDaysSincePOApproved" ...

What's wrong with my IF statement?

I'm creating an auditting table, and I have the easy Insert and Delete auditting methods done. I'm a bit stuck on the Update method - I need to be able to get the current values in the database, the new values in the query parameters, and compare the two so I can input the old values and changed values into a table in the database. Here...

Informix: procedure with output parameters??

Hi all, I searched a lot, but couldn't find anything.. I just want to ask if there's any way to create and call a procedure (Informix) with out parameters. I know how to return one or more values (for procedures and for functions), but this is not what I want. It would be really strange, if Informix does not allow output parameters.. ...

T-Sql Algorithm Question

Hello, I have a T-Sql Statement as follows; Insert into Table1 Select * From Table2 I want to know the running sequence. Does the insert waits select statement to finish before starting or it starts asap select statement starts returning values and expects new records from the select statement to continue. This is a plain stored pr...

Can a Check constraint relate to another table?

Let´s say I have one table called ProjectTimeSpan (which I haven´t, just as example!) containing the columns StartDate and EndDate. And that I have another table called SubProjectTimeSpan, also containing columns called StartDate and EndDate, where I would like to set a Check constraint that makes it impossible to set StartDate and EndD...

PhpMyadmin CSV Import data order? Mine is jubmled from CSV order?

I'm trying to import my CSV data file back into my database in the same order it is in the CSv file. However when I import the order is all jumbled from how it appears in the file. Is there a way to force PHPmyadmin to import in the exact same order as the CSV? ...

ASP MVC Delete only the relation between 2 tables (many-to-many relation)

Using ASP MVC with active record. Ive got 2 tables with records that sometimes are related and sometimes aren't. The relation is defined by the user. 1 table has projects, the other has devices. Projects can be created and deleted, devices cannot. When a user deletes a project, all relations between that project and the devices should b...

fetching the current date in sql

in the databse i have the format of the date like 'yyyy-mm-dd'. how can i fetch the current date in this format? and then if i want to calculate the date after 1 week how can i do that. thanxx in advance. Using php and mysql. ...

Grouping totals by date ranges

Hi All, I have to get totals from a table using different criteria, which I do like this: SELECT DISTINCT SUM(CASE WHEN MYCONDITION1 THEN 1 ELSE 0 END) AS TOTAL1, SUM(CASE WHEN MYCONDITION2 THEN 1 ELSE 0 END) AS TOTAL2 FROM TABLE1, TABLE2 WHERE COMMON_CONDITION1 AND COMMON_CONDITION2 AND BETWEEN DATE1 AND DATE2; This works fine an...

How can I easily store my C# data structure(XML serialiazable) into a database?

I have a C# data structure which consists of classes and collections which have references to each other. Currently I am using Serialization to store the structure in XML, which works as a handy way to save/load the structure into my application. If I want to be able to save/load the structure into a database, is there a simple way? Sho...

Versoning in relational database

Hallo all, I have a problem to introduce a good versioning in my database design. Let's make a easy example. A little rental service. You have a table Person (P_ID, Name), table Computer (C_ID, Type) and a table Rent (R_ID, P_ID, C_ID, FromData, ToData). I want to be able to change say the user name, create a new version and still ha...

Temp table with converted values

I want script to convert my table CREATE TABLE #TempTable ( Code nvarchar(5) primary key, name nvarchar(100) ) Insert into #TempTable (Code ,name) Select st.Code , st.name From StaticTable st But there is something I must change. Code must be autoincremented from 100 Where length of code is more than 3, then I want insert there i...

Set-based execution; SQL and .NET

In SQL, one should always strive for set-based operations versus iteration-based (i.e. looping). In .NET, we frequently loop collections and objects. Are there any commands in .NET that allow set-based processing or is everything iteration-based? (I'm reminded of how DataAdapter.Fill calls DataReader which iterates through each record in...

Searching for a precise term for a SQL phrase

I'm trying to document some SQL and wanted to get the right terminology. If you write SQL like so; select child.ID, parent.ID from hierarchy child inner join hierarchy parent on child.parentId = parent.ID Then you have one actual table ('hierarchy') which you are giving two names ('parent' and 'child') My question is about how you r...

How to create a trigger to record changes for Insert,Update,Delete for multiple tables.

I have two tables in my Database.This can increase later on.I want to add another table Audit to track changes to the existing two tables.I want to track any change done to any of these table AUdit Table structure is ID Table_Name Field_Name Old_Value New_Value Modified_By Date_of_Modification SO now I want to have one trigger for bot...

Query to count the exact number of records in all tables

IHello, I'm trying to count for each table in my MySQL database how many records there are in it. All of my tables happen to be in InnoDB and this query SELECT TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'myschema'; is way much too much of an estimate (There are +846 records and it tells me there are only +-400) ...

Get SQL Insert to work when PK is supplied or NOT.

Hi All I have the following stored procedure: ALTER Procedure dbo.APPL_ServerEnvironmentInsert ( @ServerEnvironmentName varchar(50), @ServerEnvironmentDescription varchar(1000), @UserCreatedId uniqueidentifier, @ServerEnvironmentId uniqueidentifier OUTPUT ) WITH RECOMPILE AS -- Stores the ServerEnvironmentId. DE...

merge of two tables from two databases

hello my friends, thanks for your attention to answer the questions. How can I merge two tables from different databases? Thanks again ...