sql

Multiple row INSERT into SQL, from text file

Hi, I have a table with 3 columns, 2 of which are auto-incrementing. I have a text file with various content that I would like to insert into the 3rd column. In that text, values are separated as such: "value1", "value2", "value3", "etc", How would I go about inserting all those values into a specific column, while being able to use th...

Selective Export of MySQL database

I have a webapp that spans many different users, each with selective permissions about what they are able to see. The app is built on top of a MySQL database. One feature I am interested in providing to my "power users" is a sql dump of all their data so that they can run off and do their own things with it. Now I can't just use mysql...

what's order when select data from database?

Suppose I have a table: CREATE TABLE [tab] ( [name] varchar, [order_by] int ) There are 10 rows in the table, and all rows have same value for order_by (Let's say it's 0) If I then issue following SQL: select * from [tab] order by [order_by] What's the order of the rows? What factor decides the row order in this case? ...

Constructing dates in TSQL

Trying to construct a date: CAST('9/1/' + YEAR(GETDATE()) AS Datetime) AS test2 But it doesnt work? Would like to get something like '9/1/2010'? ...

stored procedure column value determined by value of another column

I have a table of data something like this. date, amount, price 2009-10-12, 20, 15.43 2009-10-13, -10, 6.98 I need to write a stored procedure that will return these column as well as create a new column that indicates whether the amount was positive or negative. So the end result of the procedure would look something like this. dat...

SQL Query, SELECT Top 2 by Foreign Key Order By Date

I need a SQL query that returns the top 2 Plans by PlanDate per ClientID. This is all on one table where PlanID is the PrimaryID, ClientID is a foreignID. This is what I have so far --> SELECT * FROM [dbo].[tblPlan] WHERE [PlanID] IN (SELECT TOP (2) PlanID FROM [dbo].[tblPlan] ORDER BY [PlanDate] DESC) This, obviously, only retu...

Can MySQL convert a stored UTC time to local timezone?

Hi Can MySQL convert a stored UTC time to local timezon:ed time directly in a normal select statement? Let's say you have some data with a timestamp (UTC). CREATE TABLE `SomeDateTable` ( `id` int(11) NOT NULL auto_increment, `value` float NOT NULL default '0', `date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMAR...

UNDEFINED data type when reading SQL database from Lotus Notes using ODBC: nvarchar

Hi, This is the second time it happens to me and before modifying a 3rd party Database structure I wanted to know if anyone knew a better solution: I'm accessing a MS SQL Server 2008 from a Lotus Notes Agent (Notes 7) to retrieve some data. I use LSXODBC and my "Select" statement works perfect... Except that my agent cannot "understand...

Mysql_fetch_assoc(): supplied argument is not a valid MySQL result …

I tried everything I could think of, but I keep on getting this error. Mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /url/ on line 41 if ( $_POST[submit] == "Submit" ) { $sql="INSERT INTO table (`content`, `userid`, `ttime`) VALUES ('$_POST[content]', '".$user_id."', '".time()."')"; $r...

SQL NOT IN Clause

I have a query which is not working as expected Q1: SELECT id, name FROM vw_x WHERE id NOT IN (select pid from table_x) GROUP BY id, name Having max(c_date) > GETDATE() Q2: SELECT id, name FROM vw_x GROUP BY id, name Having max(c_date) > GETDATE() Q1 is not returning anything even though i know those ids are not in table_x Q2 run...

Displaying number of results from a MySQL db...

I have a classifieds website, and it is using MySQL as a database. My goal is to show the number of private, company and total ads in the db with the search-term entered in a text-input inside the form! The Problem: There are two types of ads: Private, and Company. The user may specify which to display, or both, so thats three options....

Does the SQL spec provide for a better way to do a exclusive ORing of two sets?

I have a result set A which is 10 rows 1-10 {1,2,3,4,5,6,7,8,9,10}, and B which is 10 rows consisting of evens 1-20 {2,4,6,8,10,12,14,16,18,20}. I want to find of the elements that are in one set but not both. There are no other columns in the rows. I know a UNION will be A + B. I can find the ones in both A and B with A INTERSECT B. I ...

What variable type should I use to save an image?

I'm going to be saving images into an SQL Database (don't know what type to use there), and I'm going to query the DB for an image of a students portrait shot. What variable type should I use to store this image? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nana_s_Student_Gradebook { ...

how many instances of SqlConnection should I use

Background: I have an application that I have nicely separated my interface logic from my middle tier logic which handles the queries to the database. I do a lot of custom sorting and narrowing so I'm not using many SqlDataSources and instead calling a lot of stored procedures with SqlCommands. I am using Forms Authentication to create...

When is referential integrity not appropriate?

I understand the need to have referential integrity for limiting specific values on entry or possibly preventing them from removal upon a request of deletion. However, I am unclear as to a valid use case which would exclude this mechanism from always being used. I guess this would fall into several sub-questions: When is referential i...

Sql custom function with Chili's opf3

I have to call a previously created function on SQL, like SET @ExtVALUE = sysdba.GetNextAccountExternalId('{TYPE}') but I can't manage to find if OPF3 has some of this functionality already. Need to use OPF3, direct access to the SQL connection is not feasible in the architecture. I think in a solution somewhat like this: var f...

MySQL - SELECTing based on an IF-statement

If I have a MySQL-table consisting of the fields one, two, three and four can I then somehow use the IF statement to receive the field four, only when a certain condition is true? Do I have to have two sets of SELECT statement? Can I do (in pseudocode): SELECT one, two, three IF (1 == 1) THEN four ENDIF FROM table Or do I somehow hav...

How long does it take to create a new database connection to SQL

Can anyone provide me with a ballpark timing (in milliseconds) for how long it takes to establish a new DB connection to SQL from C#. I.e. what is the overhead when a connection pool must create a new connection. ...

SQL server - Select all items with a date on the previous month

Hi Guys, I have a table in my SQL Server database called "items" which has a column called "dateFinished". I have a script that will run on the 1st day of each month which needs to select all items that finished in the previous month. So, for example, on the 1st February it will need to select all items where the dateFinished is great...

Trying to save changes to a SQL databse, results in "Cannot open user default database. Login failed."

I am building an MVC application with C# as my language which is hosted on Widows 7 IIS. A call to Add a new member to the database works, but when attempting to save the change I get the following error: Cannot open user default database. Login failed. Login failed for user 'IIS APPPOOL\myApplication' The SQL table was added just by a...