sql

Retrive Duplicate Row value and Count

I have table named "Table X" which contains some names and their corresponding age, table may contains same names (i.e) names will occur repeatedly. Table x: name age a 21 b 37 c 23 a 34 a 21 b 19 b 37 a 21 ...o...

how to convert a numeric value into eng.words e.g 10 to ten in sql statement?

how to convert a numeric value into eng.words e.g 10 to ten in sql statement? ...

Ansi SQL type casting

Is it allowed to cast types in ANSI SQL like in postgres for example: SELECT SUM( CAST(qnty AS int) - CAST(reserve AS int) ) AS sum ... qnty and reserve are character columns. ...

Query returns too few rows

setup: mysql> create table product_stock( product_id integer, qty integer); Query OK, 0 rows affected (0.17 sec) mysql> create table product( product_id integer, product_name varchar(255)); Query OK, 0 rows affected (0.11 sec) mysql> insert into product(product_id, product_name) values(1, 'Apsana White DX Pencil...

java ResultSet, using MAX sql function

Hello here is what I want, I connect to a DB and retrieve the biggest element of the UniqueId column, and assign it to an integer variable named maxID, here is my approach: int maxID = 0; Statement s2 = con.createStatement(); s2.execute("SELECT MAX(UniqueId) FROM MyTable"); ResultSet rs2 = s2.getResultSet(); // while ( rs2.next() )...

Nested Sets: How to query number of relations in many-to-many relationship

With a data structure like this: Tags {id, lft, rgt, depth, parentid} ObjectTags {id, tag_id, object_id} Objects {id} (the entries in Tags are organized as nested sets) I need a result that contains the Tag.id and the number of relationships that this Tag holds, including the relations of it's children but without duplicates. Exampl...

Bidirectional replication update record problem

Hi, I would like to present you my problem related to SQL Server 2005 bidirectional replication. What do I need? My teamleader wants to solve one of our problems using bidirectional replication between two databases, each used by different application. One application creates records in table A, changes should replicate to second datab...

Query did not return all rows

setup: create table product_stock(product_id integer, qty integer, branch_id integer); create table product(product_id integer, product_name varchar(255)); insert into product(product_id, product_name) values(1, 'Apsana White DX Pencil'); insert into product(product_id, product_name) values(2, 'Diamond Glass Marking ...

Sql performance on vista machine client

I have an application written in a language called magic. This application uses MSSQL Server. When it is deployed where the client is on vista machine, and the server is on a remote machine, the performance is dramatically degraded. When that same application is used from an XP client, with the db on remote machine – the performance is o...

DB down on executing delete query

Hi All, Is there a possibility that a simple delete query can bring down a DB? We executed a delete query (single row deletion) and that query hung. When multiple people tried executing the same delete again, the Oracle DB is down. Multiple tables reference this table and a cascade delete was not used. Should a cascade delete have bee...

SQL Query: How to do multiple counts?(return number of posts as well as number of topics for each forum)

I'm having some trouble getting the number of posts and topics for each of the forums on the database. I can get these values doing 2 queries but I wonder if it is possible to do it with only one query. This query gets the number of topics per forum: select forums.forumId, forums.forumName, count(*) as Topics FROM Topics INNER JOIN fo...

Tsql Get newest records from table

Hi, i have this table: Location date temp 1 12-12-2009 19 1 14-12-2009 21 1 13-12-2009 17 2 12-12-2009 18 2 14-12-2009 1...

Reading a Stored Proc not working for me when passing values.

Why is this not working for me? What is wrong with my code below? I am trying to read a stored proc and applying values to labels. Getting error that say "Incorrect syntax near CareerInner"......... Private Sub LoadData() ' Define data objects Dim conn As SqlConnection Dim Comm As SqlCommand Dim reader As SqlDataRead...

Problem with DISTINCT, SELECT and SORT in TSQL

Hi there, maybe anyone can help me out with my SELECT statement on MS SQL Server. I am not very skilled in (T)SQL. I have a table called RECORDS and with a DATETIME column called [BEGIN]. Now I would like to get some nvarchars which look like this "December 08, January 09, February 09".. I came up with the following myself. SELECT DI...

how to upate multiple rows with one single SQL statement, each to a different status

Say I have this two-column table id | column_test 1 | NULL 2 | NULL 3 | NULL ... as you see, the column_test column now all have value 'NULL'. Now I want to do an update to this table and the final status should look like : id | column_test 1 | a 2 | b 3 | c ... I know little about compound SQL state...

SQL 2005 CTE vs TEMP table Performance when used in joins of other tables.

I have a complex query that I need to use in a subsequent query (actually update statement). I have tried both using a CTE and a temp table. The performance using the CTE is horrible vs the temp table approach. Its something like 15 seconds vs milliseconds. To simplify the test instead of joining the CTE/Temp table in the subsequent q...

SQL Mass deletes

I'm trying to shrink some databases down so that my developers can load them to their local machines. I've identified several tables that hold historical data (10+ years worth) that would dramatically reduce the overall database size (50% or more) if I remove records older than X days. The delete statement that I'm using is demonstrate...

mySQL query Where issue

Could somebody tell me what am I doing wrong here? $query = "SELECT * FROM routes WHERE econ <> maxecon ORDER BY `id`;"; Without the WHERE, it works fine so I know that's the problem. I want to select data where the column econ is NOT equal to maxecon. Is this even possible at this stage or do I have...

Access 2007: Querying for DateTime field between two Short Date values

I have a form containing two text boxes for user input. Both text boxes have the Property format set to "Short Date". One is the "start date", and the other is the "end date". I also have several tables, each with a DateTime field ("studystartdatetime"). I would like to be able to query these tables, but restrict the results to rows ...

Merge result of two queries in SQL Server

I have two different queries: SELECT PB_BANK_CODE, PB_BANK_NAME FROM GLAS_PDC_BANKS WHERE PB_COMP_CODE='1' AND PB_BANK_CODE='025' AND PB_BANK_CODE IN ( SELECT DISTINCT PC_BANK_FROM FROM GLAS_PDC_CHEQUES WHERE PC_BANK_FROM ='025' AND ISNULL(PC_DISCD,'X') != 'C' AND PC_DUE_DATETIME BETWEEN '05/05/2008' AN...