sql

What is the best way to access stored procedures in Django's ORM.

I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it? ...

sql query for string contains in C#

how to write sql query to do String contains operation.? Consider, string strTest = "Hash.System.Data.DataSet has.ds"; string str1 = "Hash.System.Data.DataSet has(System.Collections.Hashtable, Int32).ds"; string str2 = "Hash.System.Data.DataSet has(System.Collections.Hashtable, System.Collections.Hashtable).ds"; Here 1)if i compare ...

SQL order by Issue-Continued

This issue is a continuation of my earlier query. It's still not working. It's about an ORDER BY clause. I am trying to sort using a variable called "sortby". Here, now the ORDER BY clause is selected as a separate column using the DECODE() function (as suggested in the answer by @devio in the original version of this question). Let’s ...

How to make a column case sensitive in sql 2005 or 2008

Is it possible to change the default collation based on a column? i want to make 1 column case sensitive but all the others not ...

Calendar using Javascript/ PHP/ mySQL

for a current webapp i need a "outlook-like" calendar... Here are some requirements for the calendar: week-view for the appointments different appointment types direct display of the length and time of the date (like in googleCalendar) multiple appointments for the same time only using javascript, php and any DB We need the calendar ...

sql query joins multiple tables - too slow (8 tables)

hi, i'm trying to join 8 tables into one in order to create index used by other application, my query is like : (my mysql skill's very amateur) SELECT t1_id, t2_name, t3_name, t4_name, t5_name, t6_name, t7_name, t8_name, t9_name FROM t1 LEFT JOIN t2 ON (t1_id = t2_id) LEFT JOIN t3 ON (t3_id = t1_id) LEFT JOIN t4 ON (t4...

Dimension Security in SSAS 2005 Cubes

Hi, I am trying to implement security in SSAS 2005 cube. I have had my share of success so far, am able to create a role and apply the ALLOWED and DENIED sets to members I wanted to apply security on. Now starts the problem - If I browse within the Analysis Services and select the role the security works as intended. But when I login a...

Automatically generate rows in DB2 with SQL

I'm trying to search the DB2 equivalent of generate_series() (the PostgreSQL-way of generating rows). I obviously don't want to hard-code the rows with a VALUES statement. select * from generate_series(2,4); generate_series ----------------- 2 3 4 (3 rows) ...

Select distinct row with max date from SQL Server table?

I need to get a set of distinct records for a table along with the max date across all the duplciates. ex: Select distinct a,b,c, Max(OrderDate) as maxDate From ABC Group By a,b,c The issue is I get a record back for each different date. Ex: aaa, bbb, ccc, Jan 1 2009 aaa, bbb, ccc, Jan 28 2009 How can I limit this so I end up w...

Under what circumstances would SQL replication partially (and silently) fail from a MSDTC Transaction from a c# application

We have a particularly bizarre problem; let me set the scene. Solution found see below We have three SQL Server 2005 databases, for the sake of argument called: Alpha, Beta and Gamma. There is a replication relationship defined between these databases as follows: All three databases have a table named "AnExample" with the same schema....

How can I compare time in SQL Server?

Hi! I'm trying to compare time in a datetime field in a SQL query, but I don't know it it's right. I don't want to compare the date part, just the time part. I'm doing this: SELECT timeEvent FROM tbEvents WHERE convert(datetime, startHour, 8) >= convert(datetime, @startHour, 8) Is it correct? I'm asking this because I need to know...

What are ways to move data older than 'Y' days to an archive/history table in MySQL?

Looking to move data from a table A to history table B every X days for data that is Y days old and then remove the data from history table B that is older than Z days. Just exploring different ways to accomplish this. So any suggestions would be appreciated. Example for variables X - 7days Y - 60days z - 365days Thank you ...

How to determine if a field is set to not null?

I have an existing program deployed where some customer databases have a field set to not null, while others are nullable. I need to run a patch to correct the database so that the column is nullable but do not need to run it against all databases, just ones where it is incorrect. Is there a simple method that can be used in SQL Server...

How to Determine Values for Missing Months based on Data of Previous Months in T-SQL

I have a set of transactions occurring at specific points in time: CREATE TABLE Transactions ( TransactionDate Date NOT NULL, TransactionValue Integer NOT NULL ) The data might be: INSERT INTO Transactions (TransactionDate, TransactionValue) VALUES ('1/1/2009', 1) INSERT INTO Transactions (TransactionDate, TransactionValue) V...

How do I get a count of associated rows in a left join in MySQL?

I have two tables, a vehicle table with columns: id stock year make model and an images table with columns: id vehicle_id name caption default tinyint(1) I am trying to list the vehicle's information, its default image, and a total count of images the vehicle has. Currently I am using the following SELECT statement: SELECT vehi...

Linq to SQL - How to find the the value of the IDENTITY column after InsertOnSubmit()

I am using LINQ to SQL to insert simple data into a table WITHOUT a stored procedure. The table has a Primary Key ID column, which is set as an IDENTIITY column in both SQL Server and in my DBML. First I call InsertOnSubmit(); with data for a single row, and then I call SubmitChanges(); to commit the row to the db. But I think there m...

SQL Count for each date

I have the following need I have a logging table which logs som leads generated each day. Now I need to pull a report over the amount of leads for each day over the last 10 days. Lets say the table looks like this: tbl_leads id int, first_name nvarchar(100), last_name nvarchar(100), created_date datetime And I need to count the num...

Concatenate a selected column in a single query?

I know you can do this, because I've seen it done once before, but I forget where and up until now I haven't need to do it. I have a table called Employees, and it has various employee data (duh). I need a query that will do a select on the first and last name of all rows in the table, and then contenate all of them into a comma delimit...

PostgreSQL how to create a copy of a database or schema?

Is there a simple way to create a copy of a database or schema in PostgreSQL 8.1? I'm testing some software which does a lot of updates to a particular schema within a database, and I'd like to make a copy of it so I can run some comparisons against the original. ...

How can I optimize this query?

How can I optimize this query? It seems there should be a much easier way to do this. The goal is that it will still be able to be readily turned into a delete statement. SELECT * FROM team WHERE team_id IN ( SELECT team_id FROM ( SELECT team.team_id, ( ...