sql

Limit a MySQL query to an even number of results (using PHP and mysqli)

Hi, I have a bit of PHP code which I need to return an even number of results from a MySQL database. I'm using the mysqli extension to execute my query. My code is approximately this at the moment: //assume we already have a database connection $query = "SELECT id FROM movies WHERE publish = 1 AN...

handling the connection string with SQL Authentication

Hello, I am deploying a Windows Application that uses SQL Server 2005. The program will use SQL Authentication. My question is, how do you handle the connection string when you don't know what the username/password will be? Do you load this from an encrypted file? Or are there provisions for handling this already? ...

What is the best way to publish c# app with PreLoaded Sql Server Express Database

I would like to distribute my C# application along with SQL Server Express 2005 and the apps corresponding database. When installed SQL Server Express 2005 needs to have my sample database automatically loaded with data, not just table structures, when it is installed. How can I accomplish this. Is there a way to do this with the Visu...

Parameterized Queries (C#, Oracle): How to produce a more readable representation?

I am using parameterized queries in my C# code to interact with an Oracle database. What can I do to log the statements in a more readable fashion? Suppose I have a parameterized query like: INSERT INTO PERSON (ID, NAME, BIRTHDATE) VALUES (:id, :name, :birthdate) Ideally I would like to see the log entry with all parameters replaced ...

SQL Server Log File Confusion

Hey all I'm looking for some clarity on the SQL Server log file. I have a largish database (2GB) which lately wasn't backed up for whatever reason. The log file for the database grew to around 11GB which from my understanding is all the transactions and statements that occurred in the database. My questions: What causes the database...

SQL Retrieve historical sensor values at specific date times

Hello, I have a database that has a vessel pressure that is trended every 30 seconds. I would like to be able to retrieve a recording at a specific time of day for a number of days in the past. I am not able to base this on the server as a Stored Procedure or a View – I only have read access. I have created a routine that works for 17 da...

Fetch records in the same order WITHOUT using ORDER BY clause

Hi, I am new to t-sql. Can someone tell me how to fetch records from a sql table in the same order WITHOUT using the order by clause? ...

Execute table-valued function on multiple rows?

Given a table-valued function such as dbo.Split() from "T-SQL: Opposite to string concatenation - how to split string into multiple records", how do I pass multiple rows as arguments? This works: SELECT * FROM dbo.Split (',', (SELECT myColumn FROM Stuff WHERE id = 22268)) WHERE ISNULL(s,'') <> '' It returns: pn s --------...

How to use LIMIT keyword in SQL Server 2005?

I have found a way to select random rows from a table in this post. A suggestion is to use the following query: SELECT * FROM employee ORDER BY RAND() LIMIT 1 But when I run this query in MS SQL 2005, I get the following error message Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'LIMIT'. Can anyone tell me where am I wr...

Selecting a large number of rows given the primary key

I need to select a large number of rows from an even larger table which is keyed on an autoincrement identity column. I have the primary key values for each of the rows that I'm trying to select, but it could be very large. Often, but not always, the rows that are being selected are contiguous, so I implemented a mechanism that convert...

Datetime To Unix timestamp

Is there anyone sitting on a PHP function to convert a date of format 0000-00-00 00:00:00(datetimesql) to unix timestamp? Thanks in advance. ...

How to make a query to a table generated by a select?

As an example: SELECT name, address, phone FROM USER; Generates the table name | address | phone ... | ... | ... How can i use this table generated to make another query to it? For example: SELECT count(address) FROM (SELECT name, address, phone, from user); I know it's not the best example, but is there any way to do th...

Is using Null to represent a Value Bad Practice ?

If I use null as a representation of everything in a database table is that bad practice ? i.e. I have the tables: myTable(ID) and myRelatedTable(ID,myTableID) myRelatedTable.myTableID is a FK of myTable.ID What I want to accomplish is: if myRelatedTable.myTableID is null then my business logic will interpret that as being linked to ...

How to find all nodes in a subtree in a recursive SQL query?

I have a table which defines a child-parent relationship between nodes: CREATE TABLE node ( ' pseudo code alert id INTEGER PRIMARY KEY, parentID INTEGER, ' should be a valid id. ) If parentID always points to a valid existing node, then this will naturally define a tree structure. If the parentID...

Is it possible to take a value from a row in one table in my MySQL database and insert into another table in the same database?

So say I have a products table with a list of products, and one of the fields is price. This table also has an id field. When someone makes a purchase I insert a row into another table called purchases. This table also has a field called price and a productid field that maps to the products table id field. I want to know if I can get the...

SQLException: fetched column value was truncated when executing while (rs.getNext())

I have a program that pulls a large dataset from Oracle 10g (10.2.0.3) using a fairly-straightforward query. You could almost call the query/logic an "export" of sorts in that it selects the columns from a table with a minimal where clause (i.e., it returns most of, if not all, the rows). The [Java] code is boilerplate that we have all...

Mixing "USING" and "ON" in Oracle ANSI join

I wrote an Oracle SQL expression like this: SELECT ... FROM mc_current_view a JOIN account_master am USING (account_no) JOIN account_master am_loan ON (am.account_no = am_loan.parent_account_no) JOIN ml_client_account mca USING (account_no) When I try to run it, Oracle throws an error in the line with "ON" self-join saying: "ORA-25154...

SQL Queries - How Slow is Too Slow?

Do you have any formal or informal standards for reasonably achievable SQL query speed? How do you enforce them? Assume a production OLTP database under full realistic production load of a couple dozen queries per second, properly equipped and configured. Personal example for illustrative purposes (not a recommendation, highly contingen...

Code reuse and modularity in SQL

Is code reuse and modulatiry a good idea for SQL Stored Procedures programming? And if so, what's the best way to add these features to a SQL stored procedure code base? I usually create scalar valued functions for tasks that are common and repeated. I find that it eases both development of new procedures similar to existing ones, but ...

How do I determine a public holiday in Sql server?

I have an application written in c# that cannot run on a public holiday or a weekend. I've looked around a bit and haven't found anywhere (official) that provide all the public holidays for the next say 50 years. If I can get these, I will simply bulk insert them into my sql server Holidays table and use that. However, I can't find ...