sql

problem with trigger in oracle

the problem is this : I implemented a trigger on the table called CLAN_AFFILIATI that increases (if inseriemento) and decreases (in case of cancellation) an attribute (NUMAFFILIATI) of another table called CLAN. what I would do is block the update NUMAFFILIATI of Clan by the user and had thought to r another trigge on CLAN that did this:...

Microsoft SQL CASE statement in where clause using LIKE

Hi, I once used a scenario where I did a SQL where clause like this: where BranchName = CASE WHEN @pBranch <> '' then @pBranch else BranchName end this is to say we're doing a branch name lookup, but this statement has to cater for the LIKE clause somehow. We need to be able to say 'If the pBranch parameter was provided then do a ...

SQL - Select next date query

I have a table with many IDs and many dates associated with each ID, and even a few IDs with no date. For each ID and date combination, I want to select the ID, date, and the next largest date also associated with that same ID, or null as next date if none exists. Sample Table: ID Date 1 5/1/10 1 6/1/10 1 7/1/10...

Iterating through dates in SQL

Hello, I have a table of data that looks a bit like this: Name StartTime FinishTime Work Bob 2010-08-03 08:00:00 2010-08-03 12:00:00 4 Bob 2010-08-03 13:00:00 2010-08-03 16:00:00 3 Pete 2010-08-04 08:00:00 2010-08-04 12:00:00 4 Mark 2010-08-04 10:00:00 2010-08-04 12:00:...

How to load a new table with the value of a variable from SSIS package?

Hi, i have two variables in a SSIS package Var1 and Var2. Both of these variables have values. is there any way i can put the values of these two variables in a new table? e.g In New table col1 having value of Var1 and col2 having value of Var2. Thanks ...

MySQL: ERROR 1064 (42000) - Why is ORDER BY failing?

as a limit 0,50 ORDER BY SortOrder, paid desc, ae desc, name asc, title asc ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY SortOrder, paid desc, ae desc, name asc, titile asc' at line 48 ...

Remove all text between 2 sentences in regex

I going crazry with regex. I need to extract a words between FROM and WHERE in this syntax: SELECT IDClient, Client FROM Client WHERE IDClient = 1 GROUP BY IDClient, Client ORDER BY IDClient result = Client How can I resolve this using regular expressions? ...

What could create a syntax error if you take a SQL query and perform an UNION with itself ?

I have this strange error in SQL Server 2005 where I take a working query, add the UNION keyword below it and then copy the query again. In my opinion, this should always be working, but it is not. I get the message 'Incorrect syntax near the keyword 'union'. What could create this problem ? To be more specific, here is the complete q...

Ruby on Rails time match database start and end times

I've been banging my head at this one: I have a table with columns start_time an end_time as well as start_date and end_date, and I have a Time object called test_time. I need to be able to match these values in a sql query. ie. Reservation.find :all, :conditions => ["'start_time' <= ? AND 'end_time' >= ?", test_time, test_time]...

Paging in T-SQL

I am trying to implement paging using Row_Number() method in this query but with no luck. The following Query uses recursive way to get Sites for a set of categories. WITH hierarchy AS ( SELECT yt.id FROM [dbo].[TH_Categories] yt WHERE yt.ID = @topicID And CultureID = @cultureID UNION ALL SELECT yt.id FROM [dbo]...

Left join with distinct values from second table

I'm trying to join two tables, one is a table of tags, and another is a table that bridges tagID and slotID. I want to create a sproc that returns the list of tags, and a column of slots that use those categories. tagDetails tagID tagDescription 1 red 2 blue 3 green 4 purple tagBridge tagID slo...

convert CSV record in column to multiple rows

select * from responses brings: 2 | user_name | green,red Can I change the query so that it brings it in the following format?: 2 | user_name |green 2 | user_name |red number of CSV values in third column varies from record to record. ...

SQL: Whats the difference between ... WHERE O.type = N'U' ... and ... WHERE O.type = 'U' ...

Today I came across an SQL statement that contains an element I've never seen. Maybe someone can elaborate? This SQL is from a stored procedure in Sybase ASE 15 SELECT O.id, OWNER = U.name, O.name, O.type FROM xxx.dbo.sysobjects O LEFT JOIN xxx.dbo.sysusers U ON O.uid = U.uid WHERE (O.type = N'U' OR O.type = N'S' OR O....

Sql 2005 get latest entry from a group of data

Problem: I have a set of data that keeps track of history of communication between clients. So each client has their own activity history (notes, emails..etc). I need to get the latest entry from each client's activity history, where each row is the latest entry from a client's activity. So every row is unique on client id and we can ca...

Import big (My)SQL file

I got a crappy connection so I can't use apps like BigDump, that would stop if I can't stay in the page. What can I do? I'm looking for a way to import without the necessity of keep connected all the time... ...

query sql and get result for foreign key's value(not id)

If I have one table: IMAGES with columns imageID, Image, and categoryID*(this being the foreign key) and 2nd table CATEGORIES with columns categoryID, Category and peform query for example: $sql = "SELECT categoryID FROM IMAGES WHERE image = 'exampleImage'"; I would get the result as an integer of the category ID i.e 1 My ques...

RegEx to match String tokens in any order?

I'm looking for an Oracle Regular Expression that will match tokens in any order. For example, say I'm looking for "one two". I would want it to match both, "one token two" "two other one" The number of tokens might grow larger than two, so generating the permutations for the regex would be a hassel. Is there an easier way to do this...

When to keep an index - Analysing index usage stastics in SQL Server 2008

I'm doing an index report on my MS SQL 2008 database (Right click database -> Reports -> Index Usage Statistics) It tells me that one of my indexes uses: 88 user seeks 0 user scans 6,134,141 user updates Can someone explain to me: What the difference between user seeks and user scans are? How should I determine when to keep an in...

SQL - columns for different categories

I am new to SQL. I have a database with data for different exams, for example: Student Test Grade -------------------- St1 T1 A St2 T1 B St3 T1 B St1 T2 B St2 T2 B St3 T2 A St1 T3 A St2 T3 C St3 T3 B Then, I would like to print a report using the Tests (T1, T2 and T3) as columns: Student ...

Pipe SQL to a file

Any idea how to pipe the results of ... DECLARE @session_name VARCHAR(200) = 'test_trace' SELECT pivoted_data.* FROM ( SELECT MIN(event_name) AS event_name, MIN(event_timestamp) AS event_timestamp, unique_event_id, CONVERT ( BIGINT, MIN ( CASE ...