sql

How to concat_ws multiple fields and remove duplicate separators for empty slots

When you CONCAT_WS(' ',field1,field2,field3) in MySQL and if one of the fields is empty, not null, you get multiple separators. An example can be: John[space][space][space]Doe[space]III. How can I make sure there is only one separator. ...

use GetOleDbSchemaTable to get the columns of a table named "Street"

I'm trying to read the column names of a table "Streets" in an Access database by opening an OleDbConnection. I call GetOleDbSchemaTable but I can't seem to figure out how to get at my columns. I'd like to use .NET 3.5 framework if possible. ...

SQL CTE and ORDER BY affecting result set

I've pasted a very simplified version of my SQL query below. The problem that I'm running into is that the ORDER BY statement is affecting the select results of my CTE. I haven't been able to understand why this is, my original thinking was that within the CTE, I execute some SELECT statement, then the ORDER BY should work on THOSE resul...

How to SELECT a column composed by some other columns value

I have a daycode column that stores values like 1,2...7 then in a different table I have cols like field1,field2...field7 I can join them on a key, but how do I select the specific fieldX column based on values passed? Table 1 has the following columns ------------- id prodno field1 field2 field3 field4 field5 field6 field7 Where eac...

Most optimized way to get column totals in SQL Server 2005+

I am creating some reports for an application to be used by various states. The database has the potential to be very large. I would like to know which way is the best way to get column totals. Currently I have SQL similar to the following: SELECT count(case when prg.prefix_id = 1 then iss.id end) + count(case when prg.prefix_...

What is the proper syntax for: WHERE strIng CONTAINS strSearch

Normally, I'd set a "Contains" filter on my string field, and enter my value in the modal box, but I want to audit the process. UPDATE Data SET Data.[Assumed Expires]=Data.[Assumed Expires]+365 WHERE Data.[Description]=strSearch; Thanks a pile! ...

How to determine which databases are being used on SQL Server 2000

I have a SQL Server 2000 box that houses several databases, some of which are probably no longer in use. I'd like to clean things up by first taking them offline, and then later removing them all together. The problem is that I don't know how to tell which of these are still being actively used (outside sources may or may not be connec...

little help with some tsql

Given following table: rowId AccountId Organization1 Organization2 ----------------------------------------------- 1 1 20 10 2 1 10 20 3 1 40 30 4 2 15 10 5 2 20 15 6 2 10 20 Ho...

asp.net/sql get everything in the string before the "-" and put it into a different string

Basically I have got two things i am passing from a command argument <asp:LinkButton ID="lbEditDetails" Text="Edit..." runat="server" CommandName="EditDetails" CssClass="EditAdults" CommandArgument=<%# DataBinder.Eval(Container.DataItem, "number_slept") & "-" & DataBinder.Eval(Container.DataItem, "booking_ref") %>></asp:LinkButton> I...

Will more MySql tables slow down searches on MySql database?

I have a classifieds website, and I am thinking about redesigning the database a bit. Currently I have 7 tables in the db. One table for each "MAIN CATEGORY". For example, I have a "VEHICLES" table which holds all information about the following categories of classifieds: cars mc mopeds/scooters trucks boats etc etc ...

Password migration SQL Server 2000 to SQL Server 2008?

I have customer registration table in SQL Server 2000, in this table have password column which is encrypted ... now I want to migrate that table to SQL Server 2008 Plz help me .... ...

Creating Table FAIL

CREATE TABLE `surfkid-db`.`Channels` (`name` VARCHAR( 30 ) NOT NULL ,`commercial` BOOL( 1 ) NOT NULL DEFAULT '0' AUTO_INCREMENT ,`usrid` INT( 5 ) NOT NULL DEFAULT '0' AUTO_INCREMENT ,`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE = MYISAM ; Error: #1064 - You have an error in your SQL syntax; check the manual that corres...

Can I optimize this sql Query?

Below is a sample query of what I am trying to do and it gets the job done but I feel like the sub queries are not the best way to go here. Any pointers? SELECT DISTINCT u.UserID, (SELECT COUNT(LoginID) FROM Logins WHERE Success = 1 AND UserID = u.UserID) AS Successful, (SELECT COUNT(LoginID) FROM Logins WHERE Success = ...

Importing data from SQL database in Excel 2003 VS Excel 2010 (VBA)

Hi, this is my first post, so I appologize if some of the formatting is not as it is usually expected. Please let me know if I've done something wrong. So, my company finally upgraded to MS Office 2010. Up untill now I've been working in 2003. I am a sql programmer, and I constantly create reports in excel that pull data from our dat...

What is the difference in these two queries as getting two different result set?

I am getting different result set for these two queries and second result set seems to be correct. What is the difference in these queries. What type of inner join query second is? 1) FROM TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.Id = t2.Id WHERE t1.StatusId = 12 2) FROM TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.Id = t2.Id AND t1.Sta...

Is there a single SQL (or its variations) function to check not equals for multiple columns at once?

Just as I can check if a column does not equal one of the strings given in a set. SELECT * FROM table1 WHERE column1 NOT IN ('string1','string2','string3'); Is there a single function that I can make sure that multiple columns does not equal a single string? Maybe like this. SELECT * FROM table1 WHERE EACH(column1,column2,column3) <>...

is there an "inverse" cascade in grails like there is in hibernate?

I have the following sql database that grails set up for me automatically. see picture for diagram http://yfrog.com/ngskillsdbj Whenever I try to delete all projects from an employee, I am getting a cascade re-save exception on the role_skill. Is that because of the way this is set up where role_skill is keyed into skill and role? I s...

Error using Liquibase on SQL Server

I'm experimenting with Liquibase, trying to get it to copy one database to another. Unfortunately, I keep getting this error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. The SQL it's generating is here: CREATE TABLE [dbo].[Attachment] ( [Applicantid] u...

How would you do this SQL query?

Let's assume I have 3 tables in a MySQL table with the following fields. product product_id product_name category category_id category_name product_in_category product_in_category_id product_id category_id What query would you recommend to get a list of all products that are not currently assigned to a category in t...

Arel causing infinite loop on aggregation

I have trouble with using Arel to aggregate 2 columns in the same query. When I run this, the whole server freezes for a minute, before the rails dev-server crashes. I suspect an infinite loop :). Maybe I have misunderstood the whole concept of Arel, and I would be grateful if anybody could have a look at it. The expected result of th...