sql

SQL Query Optimization

what are the basic principles for the query optimization in Postgres/PGSQL and oracle. Can any one elaborate it. ...

mysql group by confusion

so i have this table; mysql> describe player_weapon_stats; +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL |...

Have you ever done SQL injection?

Hi all, I want to know if you have ever performed injection on a website using SQL injection for ethical hacking. What tricks/techniques have you have used (especially mysql)? ...

Creating a new SQL entry - Updating Linked Views using VB

Hi, I am trying to create a script that automatically populates a database with existing computers. It queries the local machine for UUID and computername then creates a new record for the machine in the database. This works perfectly at the moment. The problem is, once the record is created, the linked view "ComputerSettings" isn't u...

How to create conditional destinations in SSIS Data Flow?

Goal: I have a Db source. Depending on a variable, i need to store it into a fixed width file OR a delimited file. How do I do this in a data flow? I tried creating a conditional split, with two conditions. One condition going to a fixed width destination, and one to a delimited condition. Problem is that conditional split executed BOTH...

Where clause with insert statement

Hi All, Is it possible to use where clause with insert statement. In my scenario im not getting how to use update query as the subquery returns more than one values. My query goes like this. INSERT EntityAttributeValue ( EntityID ) SELECT ID FROM (SELECT ID FROM (SELECT ID, ...

transpose columns to rows

The following query is working as expected. But how do I get the results in rows those are displayed in columns? select curdate() AS one, date_sub(curdate(), interval 15 day) AS two , date_sub(curdate(), interval 30 day) AS three , date_sub(curdate(), interval 45 day) AS four , date_sub(curdate(), interval 60 day) AS five , date_sub(...

MSQL auditing with CLR integration

Hello. I'm dot.net developer, and i'm working a lot with MSQL. My current task is when some user executes select query on database, i should "catch" the query data. What do i mean is if select query is "select * from UsersTbl where UserID = 5", i have to get '5'. Does somebody have any idea where to start??? Thanks a lot. Dmitry ...

How to select unique rows only in sql?

I have two columns, senderUserID and recieverUserID in Messages table. I select senderUserID and recieverUserID where current receiver sent a message to current sender in the past. I select 10 rows only each time but sometimes in this table senderUserID appears more than once when i need that only senderUserID will be unique, while recie...

Convert a SQL query to HQL

Hi my question is simple but may a little bit rude. Could please one of you convert two SQL Query to hql :> Select statistic.* FROM statistic INNER JOIN (SELECT MAX(st_id) AS id " + "FROM statistic WHERE status = 'N' GROUP BY bc_id) ids ON statistic.st_id = ids.id" + "ORDER BY bussinessprocessID; Select post_id, u_post_id FROM statist...

Will modifying any row data fragment my clustered index?

I now understand that a clustered index contains all of the row data, not just the index fields. I'm trying to understand the implications of this in regards to fragmentation. Say we have a table like this: create table Files ( ID uniqueidentifier not null, Field1 nvarchar(300) null, Field2 nvarchar(300) null, Field3 nv...

Help with T-sql special sorting rules

I have a field like: SELECT * FROM ( SELECT 'A9t' AS sortField UNION ALL SELECT 'A10t' UNION ALL SELECT 'A11t' UNION ALL SELECT 'AB9F' UNION ALL SELECT 'AB10t' UNION ALL SELECT 'AB11t' ) t ORDER BY sortField and the result is: sortField --------- A10t A11t A9t AB10t AB11t AB9F Actually I need ...

How can show one Row in rows in which each row contain column name and the other conatin the value ?

I have a table that contain about 60 columns and if i write a select query in query analyser to get a row it show it and i must scroll to show data .. How can i get one row in which it shows as 60 row, each row contain 2 columns one for column name and other for value For example Select * from table where id = 1 in default it shown as ...

Selecting 2 distinct rows MySQL

I have a table called categories that has 3 columns: id, name, parent_id. ID name group_id == == == 1 haim 1 2 gil 2 3 alon 1 4 idan 1 5 shai 3 6 adi 2 7 itay 3 8 aviram ...

sql query problem

Hi: I am trying to build a web log analyzer based to the tomcat log. And I first push the log to the database, then do some Statistics. Now I meet a problem: For a given data range for example (2010-09-20 to 2010-09-25), I have to calculate the visitors of each day,so I first split the data range day by day: Split:(2010-09-20,2010...

SQL - Distinct on two columns and summarized values on third

Hi! I have a table with 3 different IDs. I want to distinct on column 1 and 2 and summarize the values of column 3 (into one field - maybe comma separated string). The summarized field doesn't have to "look nice" (no problems with: '4,3,' (comma at the end)). I'm using MS SQL Server 2008. E.g: ID1 ID2 ID3 1 1 5 1 1 8 ...

Logon failed for login 'user' due to trigger execution.

I am getting this error randomly on an asp.net web application I have deployed. I am not using any triggers in the database so I am not sure what to do. This came up over the weekend when no one was in the application, it just randomly happened. Please help this is mission critical This is the first instance of where I get the error:...

SQL: Update with value from other table depending on timestamp

Hi, I have the following problem: I want to update the column "UPDATE_VALUE" of table A with values from the column "SOURCE_VALUE" from another table B. Both tables have a timestamp column, and the value that should be updated in table A should be the one of the row of table B with the highest timestamp smaller/equal than the timestamp ...

Sproc performance degrades over time

Hi, this is my first post so if you need clarificatrion on anything then just let me know. My server details are as follows: - Windows 2008 Datacentre edition SQL 2008 standard edition (10.0.1600) 12GB Ram Quad core single processor machine The problem I have a stored procedure that runs and when I have just started SQL up, it takes ...

Executing a Table-Valued Function from a Stored Procedure with multiple Table-Valued Parameters being passed through?

I've got a stored procedure that executes some repetitive code, so I decided to make the redundant code into a table-valued function. The problem that I'm encountering is: Msg 137, Level 16, State 1, Procedure Search, Line 98 Must declare the scalar variable "@myTVP". A simple example of the SQL code that I'm using is: CREATE TYPE [d...