sql

Finding data according to relevency and then take 2 result from diff domain

I am having so much domain name in my DB, for example www.yahoo.com/duniya.html www.yahoo.com/hero.html www.123musiq.com/ www.123musiq.com/home.html www.123musiq.com/horo.html www.123musiq.com/yuva.html www.sensongs.com/ www.sensongs.com/hindi.html www.sensongs.com/yuva.html www.sensongs.com/duniya.html www.sensongs.pk/duniya1.html i ...

Selecting the row before the resultset in sqlite

Hi guys. so lets say i have a table called data data id | date | name --------------------- 1 | 19/8/2010 | John 2 | 19/8/2010 | Mary 3 | 20/8/2010 | Peter 4 | 20/8/2010 | Bert 5 | 20/8/2010 | Ernie if i do a select statement like this SELECT * FROM data where date = '20/8/2010'; is it possible t...

Reading material on writing optimal SQL database queries

I have no idea whether my database queries are at all clean, efficient, and so on. At best, I can get what I need from the DB but not much else. What books (or websitse) should I read to move forward? I want to know about performance costs of the various conditions and keywords that could potentially go into a query (e.g. JOIN, IN, WHER...

Is there an way using ADO.NET to determine if a table exists in a database that works with any data provider?

Is there an way using ADO.NET to determine if a table exists in a database that works with any data provider? I'm currently doing something like this: bool DoesTableExist(string tableName) { DbCommand command = this.dbConnection.CreateCommand(); command.CommandText = "SELECT 1 FROM " + tableName; try { using (Db...

designedly big value in SQL

Ok, I have to put null values last. The query should run under Oracle and MySQL. I've already came up with ORDER BY CASE WHEN some_table.ord IS NULL THEN 9999999999 ELSE some_table.ord END I should use value > max(some_table.ord) instead of 9999999999. I think subquery to determine this value is too ugly here. If this was C+...

How to find character code in PL/SQL?

I want to find character code of particular character in string. For instance if I have a string "Hello" How do i find the character code of all or particular characters in the string. I see that PL/SQL has a ASCII() and ASCIISTR() functions but I could not find any character related functions. ...

Trouble with DELETE JOIN

DELETE FROM Books INNER JOIN (Classes, Class_Books) ON (Books.ISBN = Class_Books.ISBN AND Class_Books.Class_ID = Classes.Class_ID AND Classes.Term_ID = 63) WHERE Year = '""' Gives Error: #1064 - You have an error in your SQL syntax; Replacing DELETE with SELECT it works fine though ...

Replacing a string in a text field

Hello, I have a column in my database table which has lows of text and lows of rows. In the text, a url needs to be changed for every row. In each row the url can exist more than once. Can I use the replace function to change all the urls in the text field in my database table without affecting the rest of the text in that same col...

How to execute an SQL string directly in ASP.NET MVC 2 ?

ASP.NET MVC 2 + SQL Server Express... ...

Removing data from returned information.

Hi Guys, I am making an SQL Query that brings back a list of files and their paths. They have different file paths and different file names ofc. The file names are dates and time in the form of YearMonthDayHourMinuteSeconds. What I need to do is take the filepath that thas the latest date and time, strip off everything except the dat...

"Deep loading" with LoadWith

I have a table structure, each table with a primary key field named as "ID" and foreign key names matching their parent table's primary key. Therefore, the tables below have relationships where their primary key appears in another table and the first field in any table is it's primary key: Category -------- CategoryID Title CategoryLi...

Many to Many relationship using SQL and Linq (entity framework/to entities)

I have two tables: - Attendees - Events Normally, I would create a mapping table 'EventAttendeeMap' to link these tables into a many to many relationship. Is this the best way of doing so? Should I store the list of AttendeeIds in an xml column instead on the Events table? I am using .NET 3.5/4 with Linq as the DAL (although I think...

pivoting for two columns

HI, Using SQL server 2005 I have the following query: SELECT contact_id ,YEAR(date_created) AS giftyear ,SUM(amount_exc_vat) AS year_total_xGA ,SUM(amount_inc_vat) AS year_total_inGA ,COUNT(*) AS numGifts FROM gifts GROUP BY contact_id ,Year(date_created) Which returns data that looks like this: contac...

sql server transpose rows to column value

I have a table that looks like this: Project | State ---------------- 1 | A 2 | A 2 | F 3 | A 3 | F 3 | P 4 | S 5 | C What i would like to to is get a table like this : Project | State ---------------- 1 | A 2 | AF 3 | AFP 4 | S 5 | C Is it possible to do...

hot to access windows mobile SqlCE database from desktop vb.net

Hello, I want to access the Windows mobile SQLCE database from the desktop application when device is connected to my PC. please suggest is it possible? how i do this? Using .NET ...

SQL query for salary increase

I came up with following query which is not so challenging to resolve but still I think there might be better approach for this. Any suggessions? Thanks in advance. I have got following table tb_Salary EmpID DeptID Salary --------------------- 1  1  20000 2  1  20000 3  2  30000 4  2  800 5  2  200 I want to increase the salary of ...

Problem adding @ManyToOne mapping on Non primary-key in SQL Server

I have a problem with changing my spring/hibernate application from MySql to SQL Server. When Hibernate is updating the database by starting the server he want to creates(by hibernate.hbm2ddl.auto set on update ) the database but a foreign-key fails on following error: Unsuccessful: alter table table2 add constraint FKDC2DC97ECEB31922 ...

Parsing and modification of SQL statements in Java

Hi, Does anyone know about a SQL statements parser, in Java, that would allow having an Object representation of a SQL query, allow modifying this representation and generate back the updated SQL statement? Regards, Christophe ...

How do I convert this sql string into an ibatis sql string?

My sql string looks like this. And What I'd like to do is change it into a format ibatis can use SELECT distinct( dbo.vwChangeMgmt1.number ) FROM dbo.vwChangeMgmt1, dbo.vwChangeMgmtTask1 WHERE dbo.vwChangeMgmt1.Asgn_Group != 'WTO-AMS-NOVUS' and dbo.vwChangeMgmtTask1.Resource_group = 'WTO-AMS-NOVUS' and dbo.vwChang...

SQL - Using a join to pass a list to a lookup tbl

Hi Everyone, I want to be able to loop over a list and return a single row where all the list elements have matched. e.g. lest say my list of id's is 1,2,3 I want to write an SQL statment that will do the following (without breaking). SELECT id1 FROM TBL WHERE 0=0 AND id2 = 1 AND id2 = 2 AND id2 = 3 Is this possible? Thanks in adv...