sql

Sql Update statement issues...

I am trying desperately to create a final table for a production envirnment, however Im having some issues.... I have 2 tables in my database. MyTable has exactly the same format as the other (AnotherTable). AnotherTable has the final value that I'd like to be in MyTable. I am trying to update MyTable's gq value to equal the value in...

NHibernate calling PostgresSQL's SELECT DISTINCT ON ()

Hello, Before asking this question I have googled for some time, but could not find any relevant information on this topic. My problem is simple: I have NHibernate criteria and projection and I'm trying to set DISTINCT ON(column) My code for projection is following: criteria.SetProjection( Projections.ProjectionL...

mysql group by to return a the min value and get the corresponding row data

I have a table of data like so : - PK_table - merchantName - price - Product - 1 - argos - 7 - 4 - 2 - comet - 3 - 4 - 1 - Dixon - 1 - 3 - 1 - argos - 10 - 4 I wish to select the minimum price for a product and the corresponding merchant in mysql. I tried: SELECT...

INSERT data ignoring current transaction

I have a table in my database which essentially serves as a logging destination. I use it with following code pattern in my SQL code: BEGIN TRY ... END TRY BEGIN CATCH INSERT INTO [dbo.errors] (...) VALUES ( ERROR_PROCEDURE(), ERROR_NUMBER(), ERROR_MESSAGE(), ... ) END CATCH To make long story short some of this code mus...

update data from one table to another (in a database)

DB gurus, I am hoping someone can set set me on the right direction. I have two tables. Table A and Table B. When the system comes up, all entries from Table A are massaged and copied over to Table B (according to Table B's schema). Table A can have tens of thousands of rows. While the system is up, Table B is kept in sync with Table ...

Does this code prevent SQL injection?

Background I've been contracted to analyze an existing Data Provider and I know the following code is faulty; but in order to point out how bad it is, I need to prove that it's susceptible to SQL injection. Question What "Key" parameter could break the PrepareString function and allow me to execute a DROP statement? Code Snippet P...

How do I upload a file to a varbinary(max) column in SQL Server 2008, using TSQL?

This must be possible because I believe I've done it before. Here's my query: insert into exampleFiles Values(NEWID(), cast('c:\filename.zip' as varbinary(max)) Obviously that just inserts the text in between the quotes and not the file from that location. There must be a simple tsql bit of language that I'm forgetting. Thanks ...

Are transactions possible with HTML5 Storage in Safari

Instead of doing an each loop on a JSON file containing a list of SQL statments and passing them one at a time, is it possible with Safari client side storage to simply wrap the data in "BEGIN TRANSACTION" / "COMMIT TRANSACTION" and pass that to the database system in a single call? Looping 1,000+ statements takes too much time. Current...

ASP.NET MVC - Castle ActiveRecord - Show SQL queries

I'm using ASP.NET MVC with Castle ActiveRecord as my persistance layer. I want to know if it's possible to show the SQL queries being executed on my MySQL server. I know it's possible in a Web application using the "show_sql" property in the Castle XML configuration file, but I don't know how to do it using a Web application, since I d...

Number of days between two dates - ANSI SQL

I need a way to determine the number of days between two dates in SQL. Answer must be in ANSI SQL. ...

query to check index on a table

i need a query to see if a table already has any indexes on it. ...

Data Structure problem, don't want to store a list as text

All - I need some help designing a table for a Postgre SQL database. I have a table of products ie; CREATE TABLE products ( product_id integer PRIMARY KEY, product_name text, price numeric); INSERT INTO products (product_id, product_name, price) VALUES (DEFAULT, 'Purple Widget', '5.50'), (DEFAULT, 'Green Widget', '1.5...

Using Reserved Word TimeStamp as a field name (Firebird 2.5)

Am extending the data layer of an existing application to work with FireBird 2.5, in addition to MSSQL and SQLite, but have hit a stumbling block. I have a field called TimeStamp which stores the data/time as type TimeStamp. This works fine under MSSQL and SQLite where the type is datetime, but falls over under Firebird. The following ...

Relational database tables

Hello, I'm currently working on an ASP.Net MVC project for a software engineering class. My goal is to create a small online game rental system. I currently have a 3 tables, Movies, Games and Registrants; and I'm using LINQ-to-SQL to define each of these tables as classes for my model. So far I've created models for Movies and Games, ...

mysql join query

I have a query with the following tables (reduced to show only the interested columns). t1 code t2 code, period, status t3 period, desc Now what I have is, t3 is a table of unique "periods". t1 is a table of unique codes. t2 is the join table linking both together, along with a status, for sake of this example status=(A,B,C). Wh...

TSQL- generate a sequence number for duplicate records

Using SQL Server 2000, consider a source table with more than 400,000 records. The task is to select each regno entry with an incrementing on-the-fly rowid or sequence number for those with duplicates or multiple entries. For those which do NOT have duplicate entries in the source table, the rowid should simply be null. Here's an exam...

How to join three tables?

SELECT PC_SL_ACNO, -- DB ITEM SLNAME, -- ACCOUNT NAME: SL_TOTAL_AMOUNT -- TOTAL AMOUNT: FROM GLAS_PDC_CHEQUES WHERE PC_COMP_CODE=:parameter.COMP_CODE AND pc_bank_from = :block02.pb_bank_code AND pc_due_date between :block01.date_from AND :block01.date_to AND nvl(pc_discd,'X') IN(‘X’,...

How can I reuse a Common Table Expression

I am using a Common Table Expression for paging: with query as ( Select Row_Number() over (Order By OrderNum ASC) as TableRowNum, FirstName, LastName From Users ) Select * from query where TableRowNum between 1 and 25 Order By TableRowNum ASC Immediately after making this query, I make make an almost identical ...

PHP: display entries from Database in groups of five?

Hi, Is it possible and if so, how can I do it, to select all entries in a table in my database and then display five results at the time in one group. Meaning: A example is that I've 15 records total in my database, then I want to present my data like this: <div class="1-5">Record[1], Record[2], Record[3], Record[4], Record[5]</div> ...

Building SQL strings in Access/VBA

Occasionally, I have had to build a SQL string in VBA and execute it with Docmd.RunSql(). I have always built these strings by concatenating variables into the string, e.g: Dim mysqlstring as String mysqlstring = "INSERT INTO MyTable (Field1, Field2, Field3 ...) VALUES (" mysqlstring = mysqlstring + Me.TextMyField1 + ", " 'parameter com...