sql

Building a MYSQL query based on multiple unique listings

Sorry for the crappy title - didn't know how else to say it. I have a commenting database where anyone can report a comment for abuse (anyone as in not just logged in members). This obviously means a person could report a comment multiple times. Where I need help is building a query that shows the number of times a comment has been re...

What is the SQL to delete a SQL User from a database?

What is the SQL to delete a SQL User from a database? ...

Rails find and sort using natural sort order collation

I want to return a paginated list of countries with Åland coming after Azerbaijan instead of after Zimbabwe. In other words, I want to ignore special characters and simply treat an "Å" as an "A" and the "ô" in Côte d'Ivoire as a regular "o". Is there a Rails method or gem to do this or do I need to execute some kind of custom SQL (and if...

Netezza Sql query

Hi, I have a list of tables in a Netezza database and I want to get the name of primary key for each of the tables. Can anyone provide me the query. ...

Why does this simple mysql insert query take occasionally so long?

Ok, I've got a real head scratcher... I'm going bald! This is a pretty simple problem. Inserting data into the table normally works fine, except for a few times, the insert query takes a few seconds. This isn't very good, so I setup a simulation of the insert process. I am NOT trying to bulk insert data. I am trying to find out why...

Remove duplicate entries from database with conditions

I've had a good look around but havnt been able to find a solution so hoping someone can help with this one. I have a MySQL table of results from an internal logging application which records a result from a check routine, there are a number of check routines which are identified with the tracker column: id (int)(PK), tracker (int), ti...

[SQL Server Procedure] Cannot user "Select TOP @Count ..."

I am creating a procedure something like below. it works fine when there is no "TOP @Count", or it works fine when i put a concrete vaule "TOP 100" . So why i cannot pass the value there??? how can i walk around it??? SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE MyProcedure @Count int = 100 AS BEGIN SELE...

Why is this Linq Query returning 3 identical rows from the same SQL view?

I have a simple view defined MSSQL 2008. The view is defined as follows: SELECT dbo.tblCompany.CompanyID, dbo.tblAccount.Carrier, SUM(ISNULL(dbo.tblLine.LineCharge, 0)) + SUM(ISNULL(dbo.tblLine.FeatureCharge, 0)) + SUM(ISNULL(dbo.tblLine.AccessCharge, 0)) AS SumOfCharges FROM dbo.tblCompany LEFT O...

Using SQL Report Builder 2.0 to group by Parents/Children

Hello, this is my first post, so I hope I get everything right... I am trying to generate a report that shows a summary of items held for each customer in our database. Our customers can have children companies, so I need the report to group on the parent company, then show the children and their sums, and then show the total for the P...

JDBC: in set condition: can I pass a set as single param?

In JDBC I can use question marks for query parameters, like this: "SELECT * FROM users WHERE login = ?" and then ps.setString(1, "vasya"); But how can I query for list of logins: "SELECT * FROM users WHERE login IN ?" suppose, I have List<String> logins = ... What should I type there: ps.setWhat(1, what); I could rewrite q...

SQL to find runs of matching values

I have the following table called [Store_Sales] - Store Date Sales 1 23/04 10000 2 23/04 11000 1 22/04 10000 2 22/04 10500 1 21/04 10000 2 21/04 10550 I want a SQL that will return a "run" of similar values in the Sales column for a particular store. For exampl...

How not to insert specific value into database

I have MS SQL Server database and insert some values to one of the tables. Let's say that the table contains columns ID, int Status and text Text. If possible, I would like to create a trigger which prevents from writing specific incorrect status (say 1) to the table. Instead, 0 should be written. However, other columns should be prese...

How to write the sql to findout which value is not in the table?

I am having a table Student and i have a set of 20 names. by using his sql select name from student st where st.name in ( 'abc', 'xyz', . . . ) i can find out all student names which are in table and in the set. Now, how can i find out which out of these 20 names are not in Student table. ...

Is there a better way to extract the time of day ?

I'm trying to extract the time of day from a 'timestamp' column in PostgreSQL. Here is how I did it but... it's awful. An idea of how to do it better ? SELECT ( date_part('hour', date_demande)::text || ' hours ' || date_part('minute', date_demande)::text || ' minutes ' || date_part('second', date_demande)::text || ' seco...

Runtime Error '3709' while accesing SQL database in VB6

I have a VB6 application which someone wrote, which does not work for only some users who try to use it. This is the code running which returns an error: On Error GOTO error_handler .. Set db = New ADODB.Connection db.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=****;Password=****; Initial Catalog=***;Data Source=*...

Input string was not in a correct format. on SQL Select like Statement?

I Created this Select Stored Procedure: @SerialNumber varchar(50) @PalletNumber varchar(50) ------> Datatype int SELECT ,SerialNumber , PalletNumber FROM dbo.FG_FILLIN WHERE (SerialNumber LIKE @SerialNumber + '%' ) AND (PalletNumber = @PalletNumber) I change @palletnumber to varchar because Like '%' doesnt accept int. ...

Command Text property has not been initialiazed

This one is a tricky one I have been looking through the event viewer on our server and can see quite a few people with this error but I can't replicate this myself but it is causing issues for people viewing our website is there anyway I can "initialize" Command Text property? Thanks Jamie UPDATE So I have this query datelistquery...

How to rewrite this query not to use union clause

How to rewrite this query NOT to use UNION (UNION ALL) clause: SELECT c FROM a UNION SELECT c FROM b expected result (recordset should be the same): SELECT c FROM .... ...

How to reference a map name for a subquery in an HQL order by clause

I've got an HQL statement like this: select new map (f1 as field1, (select ...) as field2) from ... where ... order by field2; It fails saying "Unknown column 'field2'". I experienced this in general that when using the "new map" statement, I can't reference the map names in the order by field. As HQL subqueries are only allowed in t...

Suppress transaction in stored procedure

Hi all, I want to know wether or not it is possible to suppress a transaction inside a SQL stored procedure. I have the following situation in my SP (that I want to achieve): WHILE TRUE BEGIN TRY BEGIN TRANSACTION A RECEIVE MESSAGE FROM SSB QUEUE WITH TIMEOUT BEGIN SUPPRESS TRANSACTION WHILE RECORD IN TABLE ...