sql

T-SQL Get file via HTTP?

Is it possible to grab a file using T-SQL via HTTP? I'm familiar with grabbing a file via FTP using a script and xp_cmdshell. I want to do the same thing except the file is only available via HTTP. My guess is that it's not possible. If not, what are some alternatives? wget for Windows? My goal is to get the file onto the SQL serve...

Why is my index getting fragmented?

I have a simple little table (just 8 fields) an hour ago I rebuilt one of the indexes on the table, which reset it to 0% fragmentation, but now it’s up to 38%. The table itself has 400k records in it, but only 158 new ones have been inserted since I rebuilt the index, there have been no updates to records but perhaps a couple of deletes...

'Database may not be activated yet or may be in transition' error

I have this heavily nested sql statement which works well in my sql server 2008 express. [code block below] However, when I move it over to our preliminary test server (sql server 2000) it doesn't work unless I use fully resolved table references in the from clauses of each statement. Which I can't do as the database name varies by inst...

Using union and count(*) together in SQL query

Hello I have a SQL query, looks something like this: select name, count (*) from Results group by name order by name and another, identical which loads from a archive results table, but the fields are the same. select name, count (*) from Archive_Results group by name order by name How would I combine the two in just one query? (S...

Postgres encoding "UTF8" error whilst inserting images via Java

Hi I am inserting jpeg images into my UTF-8 encoded Postgres database into bytea column/s. I'm using a prepared sql statement to insert the images. In the statement I create a file object, within Java, of the jpeg image and then pass it as a FileInputStream into the setBinaryStream method. However every now and again my Java app will th...

SQL - two months from todays date in Oracle

I have a column that stores the last modified date. I want to check in a SQL query if its value is more than 2 months from the current date. I know I need to use SYSDATE but am not familiar with date stuff in Oracle so am unsure as to the rest. ...

OPENXML Remote Scan Performance

I'm looking for some advice on OPENXML. Specifically, the performance. I am seeing very slow performance on a very small piece of XML. Something about this is causing a Remote Scan. Any ideas on how to go about tuning it? DECLARE @idoc int EXEC sp_xml_preparedocument @idoc OUTPUT, @ResourceXML DECLARE @tmpRes TABLE (ResourceID...

mysql delimiter error

Modifed. DROP FUNCTION IF EXISTS PersonName; DELIMITER |; CREATE FUNCTION PersonName( personID SMALLINT ) RETURNS CHAR(20) BEGIN DECLARE pname CHAR(20) DEFAULT ''; SELECT name INTO pname FROM family WHERE ID=personID; RETURN pname; END; | DELIMITER ; whats wrong with this code? i get following error with it. There seem...

MySQL DATE_ADD - date is wrong?

So I've got a simple query in MySQL that sets a new member's expiration date once they pay their dues: UPDATE members SET joined=CURDATE(), expires=DATE_ADD(CURDATE(), INTERVAL 1 YEAR), active='1' WHERE id=1000 this query has run 200+ times, normally with the correct result - the current date is put in the joined field, and a year fro...

SQL: Insert all records from one table to another table without specific the columns

I want to insert all the record from the back up table foo_bk into foo table without specific the columns. if i try this query INSERT INTO foo SELECT * FROM foo_bk i'll get error "Insert Error: Column name or number of supplied values does not match table definition." Is it possible to do bulk insert from one table to another witho...

SQL Server (2005) Linked Server Issue

I have SQL Server 2005 with several linked server defined. One of them is a connection to an Oracle server and another one is an ODBC bridge to another server on a remote machine (ODBC server). Recently I tried to use the linked server to Oracle to update data with two large size tables by using several joints. The update query took too...

Top 10 SQL Server performance bottlenecks

What is the most common performance bottleneck that is not caused by the database structure? ...

How do you insert a record with a nullable column ?

How do you insert a record with a nullable column ? ...

SQL Update Multiple Fields FROM via a SELECT Statement

This works, but i would like to remove the redundancy. Is there a way to merge the update with a single select statement so i don't have to use vars? DECLARE @OrgAddress1 varchar, @OrgAddress2 varchar, @OrgCity varchar, @OrgState varchar, @OrgZip varchar, @DestAddress1 varchar, @DestAddress2 varchar, @DestCity varchar, ...

Which conditional statement is faster in SQL?

SELECT a, b FROM products WHERE (a = 1 OR b = 2) or... SELECT a, b FROM products WHERE NOT (a != 1 AND b != 2) Both statements should achieve the same results. However, the second one avoids the infamously slow "OR" operand in SQL. Does that make the 2nd statement faster? ...

Mysql only imports a single row from CSV

Development machine is a Mac. I'm having some trouble importing more than a single line from a CSV into Mysql. Here is my SQL statement: LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE students FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (pita, dob, name, grd, asst, loc); It runs fine, but only one record is imported. Any idea whe...

SQL statement with several joins

I must be honest and tell you that I am not good at database queries and this question is probably quite simple. I have three tables Post ID entry Category ID name CategoryBinding ID postID categoryID My normal query is to get all posts with the categories it is put into SELECT * FROM `Post` AS `p` LEFT ...

SQL select and count all items that have occured before

I have a table with rows that symbolize order dates: 2009-05-15 13:31:47.713 2009-05-15 22:09:32.227 2009-05-16 02:38:36.027 2009-05-16 12:06:49.743 2009-05-16 16:20:26.680 2009-05-17 01:36:19.480 2009-05-18 09:44:46.993 2009-05-18 14:06:12.073 2009-05-18 15:25:47.540 2009-05-19 10:28:24.150 I would like have query that returns the ...

How do I use a temp table across multiple c# calls.

I have a C# application, using ADO.Net to connect to MSSQL I need to create the table (with a dynamic number of columns), then insert many records, then do a select back out of the table. Each step must be a separate c# call, although I can keep a connection/transaction open for the duration. ...

How to write SQL Query that matches data from a .csv file to a table in MySQL?

Is it possible for me to write an SQL query from within PhpMyAdmin that will search for matching records from a .csv file and match them to a table in MySQL? Basically I want to do a WHERE IN query, but I want the WHERE IN to check records in a .csv file on my local machine, not a column in the database. Can I do this? ...