sql

stored proc return all rows when parameters are null

when the optional parameters are null or empty how can i ignore that condition? e.g. declare @color nvarchar(50) declare @time datetime set @color = null select * from apples where apple.color = @color and apple.time = @time if @color or @time is null , i would like to ignore that condition. ...

Group by in SQLite over one subset of a set based on the elements of another subset of the set...

I have a dataset something like this A | B | C | D | E ----------------------------------------------- 1 | Carrot | <null> | a | 111 2 | Carrot | <null> | b | 222 3 | Carrot | zzz | c | 333 4 | Banana | <null> | a | 444 5 | Banana | ...

How to store SQL query results for fast access ?

Hello, SQL beginner here. I have a query which takes around 10 seconds to run, so we have a slow down in the application. Would it be possible in MySQL or more generally in SQL for the server to periodically (every 1 to 5 minutes) run the query and store it somewhere, so that I can query this "cache" table for easy access ? Many tha...

what is the difference between oracle "create or replace type" and "type type_name is..." syntax

hi guys, i'm a pl/sql newbie. now i have a question about oracle type. i saw there are two types of type : CREATE OR REPLACE TYPE "TYPE_NAME1" AS OBJECT ( temp_trans_id number(10), trans_id number(10), resion_id number(10) ) or type new_type_name is record( column1 number, co...

ER Diagram (Drawing)

For a relational database that represents the current term enrollment at a large university, what is the ER diagram for a schema that takes into account all the assertions given: • 100 instructors, 200 courses, and 800 students. • An instructor may teach one or more courses in a given term (average is 2.0 courses). • An instructor mus...

MySQL: Getting highest score for a user

I have the following table (highscores), id gameid userid name score date 1 38 2345 A 100 2009-07-23 16:45:01 2 39 2345 A 500 2009-07-20 16:45:01 3 31 2345 A 100 2009-07-20 16:45:01 4 38 ...

Creating database tables with "either or" type fields.

I have a database that tracks players through their attempts at a game. To accomplish this, I keep a table of users and store the attempts in a separate table. The schema for these tables is: CREATE TABLE users ( id BIGINT PRIMARY KEY, -- the local unique ID for this user name TEXT UNIQUE, -- a self-chosen username for the user ...

SQL Question: It's possibile to have a WHERE clause after a HAVING clause?

So... It is possibile to use a WHERE clause after a HAVING clause? The first thing that comes to my mind is sub queries, but I'm not sure. P.S. If the answer is affirmative, could you give some examples? ...

Oracle - Java - wrong number or types of arguments in call to 'SP_GET_MENU_PARENTS'

Hi, Below is my Oracle Procedure. When i call this procedure using java, it throws error like this. CREATE OR REPLACE PROCEDURE sp_Get_Menu_Parents ( v_inMenuID IN VARCHAR2 DEFAULT NULL, cv_1 IN OUT SYS_REFCURSOR ) AS BEGIN OPEN cv_1 FOR SELECT MenuItemId, MenuItemName, MenuItemDisplayName, ...

if else condition for update a table in a storeprocedure in sqlserver2005

I want to update some data in a specified case, else these fields are not to be updated. What can i write code in a stored procedure for this? ...

code for update

My table name is table_1, fields are: name dept location status Status is already 1, but I want to update the status into 2 based on a certain condition else not update. My code is UPDATE Table_1 SET model = @model, make = @make, [Asset Serial No / Service Tag] = @Asset, [IT Asset Tag] = @AssetTag, ...

SQL Server: How to extract comments from stored procedures for deployment

We have lots of stored procedures which all contain a lot of comments. Is there a way to extract the comments from the stored procedures for deployment so the users can't see them when they modify a stored procedure with SQL Server Management Studio? Note: We're using SQL Server 2008. ...

hibernate many-to-many

Hi, i have three tables and 2 JPA model classes: Unit ------------ id [PK] - Integer code - String unitGroups - List<UnitGroup> UnitGroup ------------ id [PK] - Integer ugKey - String units - List<Unit> units and unitGroups have many-to-many relationship between themselves. briefly i want to write an HQL query...

Materialized view with Oracle

Hello ! I have the following line in a script and I don't understand what the "using" part is used for. I couldn't find anything on google. Anybody familiar with that ? Thanks a lot !! CREATE MATERIALIZED VIEW "PVTRNDM"."DM_MVW_DAILY_CAL" USING ("DM_MVW_DAILY_CAL", (8, 'PLANVP.XXXX.INT', 1, 0, 0, "PVTRN", "DAILY_CAL", '2009-...

SQL Compact import DB from SQL Server Express with Server Management Studio

Hi! I try to import sql script, generated with Server Management Studio, into SQL Compact 3.5 and get a lot of error. What I am doing wrong? I generate script with "Task/Generate Script" context menu. Part of my script: CREATE TABLE [LogMagazines]( [IdUser] [int] NOT NULL, [Text] [nvarchar](500) NULL, [TypeLog] [int] NOT NULL, [Date...

SQL returning extra data.

Hey there, was wondering if anyone could help a newbie on SQL and Python. I thought I had a pretty decent grasp of it, however something odd happened recently. Here is the the following code snipped from a larger portion: try: self.db.query("SELECT * FROM account WHERE email = '{0}' AND pass = '{1}'".format(self.mail.strip(self...

Efficient way to store content translations?

Suppose you have a few, quite large (100k+) objects in available and can provide this data (e.g. name) in 20+ languages. What is an efficient way to store/handle this data in a SQL database. The obvious way to do that looks like this - however, are there other ways which make more sense? I'm a bit worried about performance. CREATE TA...

How does one configure PHPUnit to log to the test database?

Hi All I am trying to work out how to configure PHPUnit to use the "test database" that is described on this wiki page: http://www.phpunit.de/wiki/TestDatabase However I can't find any documentation on how to enable and configure it. Has Anyone got any ideas? Thanks ...

how to structure an index for group by in Sql Server.

Hi, The following simple query takes a very long time (several minutes) to execute. I have an index: create index IX on [fctWMAUA] (SourceSystemKey, AsAtDateKey) SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem] FROM [fctWMAUA] (NOLOCK) AS [t0] WHERE SourceSystemKey in (1,2,3,4,5,6,7,8,9) GROUP BY [t0...

SQL DateTimes From C# Linq to Stored Procedure

I have a complex sql query that I have in a stored procedure and am calling from C#. The procedure requires a date-time which I pass in as DateTime object from c#, the problem seems to occur with the format of the date. If I change the parameter to string and pass it in as 'yyyy-MM-dd' it works fine. Is there anyway to use the datetim...