sql

SQL help: select the last 3 comments for EACH student?

I have two tables to store student data for a grade-school classroom: Behavior_Log has the columns student_id, comments, date Student_Roster has the columns student_id, firstname, lastname The database is used to store daily comments about student behavior, and sometimes the teacher makes multiple comments about a student in a given da...

Prepared statement with "partition by" doesn't work against Sybase IQ?

I'm seeing a problem when querying Sybase IQ with a prepared statement. The query works fine when I type the entire query as text and then call PrepareStatement on it with no parameters. But when I stick in one parameter, then I get back errors, even though my sql is correct. Any idea why? This code works perfectly fine and runs my que...

SQL: sum 3 columns when one column has a null value?

SELECT sum(TotalHoursM) + (TotalHoursT) + (TotalHoursW) + (TotalHoursTH) + (TotalHoursF) AS TOTAL FROM LeaveRequest ...

Invalidcastexception error while using set or bag cascading

Hi guys, I have a parent class which contains a child object. I am using set to save the child object when parent is saved. I m not sure whether set is used for just saving a child object. And im getting this error below System.InvalidCastException: Unable to cast object of type 'x' to type 'Iesi.Collections.ISet' Does anybody knows th...

SQL Server Index performance - long column

In SQL Server (2005+) I need to index a column (exact matches only) that is nvarchar(2000+). What is the most scalable, performant way to approach this? In SQL Server (2005+), what would be the practical difference in indexing on a column with the following types: nvarchar(2000) char(40) binary(16) E.g. would a lookup against an ind...

Teradata locks - How to know if a table is locked ?

Is there a way to know if a table is locked and what kind of lock is currently on a table? I was hoping for something through the DBC tables in teradata, but I can't find any reference to anything like this. I have normal user access and the DBA is no help. Thanks. ...

SQL Server 2000 - How to find out what indexes are in use?

In SQL Server 2000, how can I find out what indexes are being used? I can find a list of all the indexes easily enough, but how do I know which ones can be removed because they are no longer used? I don't want to slog through all the sql used on our server running explain plans to find this out and also risk missing something. ...

Do Indexed Views Update During a Transaction?

Let's say I've got a SQL Server Indexed View, vwIndexedView, that reads from two tables, tbTableOne, and tbTableTwo. If I perform an action on one of the two tables inside a transaction, what happens to my indexed view? Is it refreshed immediately, or do I have to commit my transaction before the results will feed into it? For instance...

Insert into a table a part of another table

I have two tables, the structure of the first partially recapitulates, iterates the structure of the second: table1 (id, i, j, k, a, b, c, x, y, z) -- requests table2 (id, a, b, c, d) -- essential elements / bank subjects I need to insert into table1 a record from table2 with given ID. What is the best approach to do that? I have two...

Pivot Queries in a UNION

Pivon queries, love em. Turn rows into columns. I need to do a pivot query on the union of 3 other queries. How do I structure this? I already know the names of the fields in the rows I want to transform but where do I put the pivot statement so it works? ...

EAV Solutions/Packages/Vendors?

I was recently exposed to the concept of an Entity Attribute Value database model via. the Magento e-commerce system. Varien (the company behind Magento) has used a relational database (mysql) to create an EAV style model using PHP Objects. I'm curious if there are "native" EAV database solutions out there. The "featured recently on ...

SSRS Report from Oracle DB - Use stored procedure

I am developing a report in Sql Server Reporting Services 2005, connecting to an Oracle 11g database. As you post replies perhaps it will help to know that I'm skilled in MSSQL Server and inexperienced in Oracle. I have multiple nested subreports and need to use summary data in outer reports and the same data but in detail in the inner ...

How to create a search engine with filters?

I'm trying to create an online search for a particular set of literature/quotes/etc from a spiritual organization, and while the number of items (mostly PDF, HTML, or plain text) that can be searched is limited, I wanted to provide comprehensive search filters (Kayak.com style). That means my data will need to be organized in such a ...

Under what conditions does ROWNUM=1 significantly increase performance in an "exists" syle query

I read some of the discussion in this question and thought to myself that in my PL/SQL code I have "exists" style queries all over the place that don't use the ROWNUM=1 optimisation. The questions I have are: Does the introduction of ROWNUM=1 significantly increase performance? If so, under what conditions would performance be particu...

IN SSMS how do I script a stored proc with a Drop Section and a Create Section?

For our deployments, I just want to drop the existing stored proc, then re-create in the same script. The script wizard only seeems to give me a mutually exclusive option - I'm looking for a Drop-Then Create Option. Am I missing something? ...

adding sql query output to hyperlink in asp.net

I think it might have been asked before but i was unable to find the right answer, so i am asking here. i have added a data source which is working fine, i wanted a feature where i query the top n entries from the database and add it with a hyperlink. Think of it like Latest News! The markup for the hyperlink inside the ItemTemplate of D...

How to maintain subcategory in MYSQL?

I am having categories as following, Fun Jokes Comedy Action Movies TV Shows Now One video can have multiple categories or sub categories, let's say VideoId: 23 is present in Categories Fun, Fun->Comedy, Action->TV Shows but not in Action category. Now I am not getting idea that hwo should I maintain these categories in Database....

Article compatibilty in SQL database

Hi, I'm pretty fresh to database handling, but now completely without experience. However, I have gotten stuck on a problem. I need to formulate an SQL query that returns all articles that are compatible to a set of other articles (of arbitrary size). The query is to be generated by a script in an application to search for articles whe...

SQL Select - return as one

I have a select query. I want to replace that select query with another select if that returns no rows. For instance lets say I have: Select * from Temp2 if (@@rowcount=0) select * from Temp1 At the c# end, I retrieve it as a dataset. So if no rows are returned, it would do another select. But this select would be in Tables[1] not T...

Cross Database SQL Scripts

I'm working on a project where we talk directly from one database to another. We have a master database where the client updates their website and then changes are pushed from one database to the other through numerous SQL scripts. The master database works as a preview site allowing them to see changes before pushing them to live. At t...