sql

Is that possible to INNER JOIN more than one table?

Using: SELECT * FROM cart INNER JOIN dkb ON cart.id = dkb.id WHERE cart.cookieId = '" . GetCartId() . "'" Besides the dkb table, I want to INNER JOIN the cdkb table using ON cart.id = cdkb.id. How would that be displayed when cdkb added to the existing query? ...

alternative of TOP keyword in mysql

Hi, I want to know the alternative of the TOP keyword as in mysql. I have read about Top Keyword in SQL. Is there any alternative for that in MYSQL. Or any other method in mysql from which we can get same functionality. Thanks Avinash ...

How to rearrange the following data using php?

i retrieved the following data using sql query from mysql TOTAL COMPUTER DATE GROUP ----------------------------------------------- 48 LAPTOP2 2009-08-19 1 77 LAPTOP2 2009-08-20 1 0 LAPTOP2 2009-08-21 1 15 LAPTOP1 2009-08-19 1 25 MAIN 2009-08-...

Stored procedure, datetime

I have a search form in a website where I have to do a search in all or one column to database. I have the following stored procedure and have problem with datetime. How will I do to allow it to be null? I have problem with this both in stored procedure and i codebehind c#. Hope you can help me! ALTER PROCEDURE [dbo].[SearchPostit] ( ...

Why does this cause an oracle error? ORA-00907

This is driving me insane, can anyone help me understand why the following statements all return the following error? create table JMS_PENDING_MESSAGE (id number primary key, queuex nvarchar2(200), messagex nclob(1000)); create table JMS_PENDING_MESSAGE (id number primary key, queuex nvarchar2(200), messagex nclob(10000)); create table ...

How to remove all parrents with no children in SQL?

I have a table that has id, name, level (the depth) and parrent_id, is there any nice way to remove all nodes without any children? (On one level suffices)? I know I can do it in application - load all the nodes on given level and the check if they have children, if not remove, but this whould probably be more effective in SQL and I'm no...

Should I run VACUUM in transaction or after?

I have a mobile application sync process. The transaction does a lot of modification on the database. Since this is done on mobile I need to issue a VACUUM to compact the database. I am wondering when should I issue a VACUUM in the transaction, as final statement or after the transaction? I am currently looking for SQLite, but if i...

MYSQL top N rows from multiple table join

Like, there is top keyword in sql server 2005, how to select top 1 row in mysql if i have join on multiple table & want to retrieve extreme of each ID/column. Limit restricts the no. of row returns so it can't solve my problem. ...

SQL Server : Invalid cursor state (0) state why ?

I have a table on which there is update trigger written it has print statement before go statement. ALTER TRIGGER user_type_check ON user_table --code PRINT 'Modification of user is done.' GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO Now with this structure whenever i perform update operation on the table it fai...

Is there an equivalent to typedef in Transact-SQL?

Is there any way of aliasing datatypes in T-SQL (SQL Server 2005), a bit like a C typedef? I'd like to be able to alias, say, VARCHAR(20) as 'my_datatype' so that wherever I wish to use VARCHAR(20) I could instead use my_datatype. Synonyms allow you to do this sort of thing for tables, and there are built-in synonyms for some datatypes ...

MYSQL merge columns

I'm using MySQL and do a select: SELECT LTRIM(Firstname + ' ' Lastname) AS Fullname FROM Persons My result is 0 for every result. Even if i remove the LTRIM, Using CONCAT is giving the same problem. ...

How does a swapping data between two tables in SQL Server work?

I could probably google this, but it seemed quirky enough that it might be worth having logged as an answer on SA. So in development land, if you want to swap interchance the values of two variables, you need a third temp variable. e.g. string x = "ABC"; string y = "DEF"; string temp; temp = x; x = y; y = temp; However in a SQL Up...

SQL TOP 10 Ranking Query Help Required

Hi Everyone I have the code below and I am trying to find out the top 10 servers used in the last month, but having issues, not very good with SQL. Need some help or advice if possible. I got this working on top 10 Apps but cannot figure out how to make this happen for top 10 servers. SELECT TOP 10 dbo_LU_SERVERNAME.SERVERNAME, Count(...

Count days in several time ranges

I need to count the number of days that fall completely or partially within a set of time ranges. The ranges do not overlap but there may be many in the same day. For instance, given: +---------------------+---------------------+ | time_start | time_end | +---------------------+---------------------+...

LINQ Stored Procedure DATETIME NULL

I got this errormessage when I use Linq and and stored procedure as follow. I got this message when the DateTime parameter is NULL. How will I do to solve this? Errormessage Serverfel i tillämpningsprogrammet. SqlDateTime-spill: Det måste vara mellan 1/1/1753 12:00:00 AM och 12/31/9999 11:59:59 PM. Codeblock in C# protected void Butt...

Problem when using form-reference in transform/pivot query

Hi! When the query is like this there is no problem This works: TRANSFORM Count(Aktivitet.ID) AS AntalförID SELECT Aktivitet.region, Sum(Aktivitet.antalMän) AS [Antal Män], Sum(Aktivitet.antalKvinnor) AS [Antal Kvinnor] FROM Aktivitet GROUP BY Aktivitet.region PIVOT Aktivitet.aktivitetstyp But when I add this line I get into trouble...

Generate Reports from Ms Access 2007 Using Queries automatically via VBA

Hi Everyone, I have a few queries which need to be exported into a report and I want this to be done automatically each time the database is opened. I'm guessing this would be possible using VBA to which i dont have much knowledge off. Can anyone help with this please? Thank You ...

Counting Rows between dates...

I'm using a CTE to generate a range of dates. 12/02/2010 10:00:00 12/02/2010 10:59:59 12/02/2010 11:00:00 12/02/2010 11:59:59 12/02/2010 12:00:00 12/02/2010 12:59:59 I then left join this to a indexed view containing huge amounts of date. I have 2 options for counting between the date ranges 1) i would SUM(case) test the log_date t...

Sql Server query with date filter

I have a table like this; ID int, OrderedDate DateTime I want to select only records of followed month. For example result set: ID OrderedDate 110 January 110 February 200 January 200 February How can I write this query? ...

Ranking before grouping problem in SQL Server 2005

HI, This should be easy but I don't understand enough about how grouping works. Basically I have 2 tables "Categories" and "Items" Categories ID CategoryName Items ID CategoryID ItemName Photo Score All I want to do is get 1 row for each category which contains the Category ID, the Category Name and the photo that belongs to the h...