sql

Mysql query help in group concat

I have three tables 1. MetaKey Colmans: ID KeyName 1 hobbies MetaKeyValue Colmans: ID KeyValue: 1 skating 2 rugby 3 TV ObjectType ID ObjectName 1 World 2 Branch 3 Customer MapMetaKeyMetaValue Colmans: ID KeyID ValueID ObjectID(Branch or Customer ) ObjectTypeID isLive -------------------------------------------...

Getting around the lack of a Left Trim(string, char[]) function in JET / Access

I need to remove leading zeros from a string field in an Access database that is destroyed and recreated every time it is used within a C# program. Most string libraries (even SQL ones) include a Trim function to remove leading or following whitespace. Unfortunately, Access does not seem to have a LTrim(string s, char[] trimChars) or som...

SQL: problems with like and NOT LIKE

i have this statement in access: SELECT * FROM accountsnew WHERE [Panels] not like '*IT_OXYC,*' and [Panels] not like '*OXY_SN,*' and [Panels] not like '*OXY_S,*' and [Panels] not like '*OXY_N,*' and [Panels] like '*OXYC_SNEG,*' or [Panels] like '*OXYC_PNEG,*'; for some reason it is not returning the proper dataset. when i look more d...

Splitting a delimeted string with 2 values .SQL Server 2008 . Can you help?

I am passing a delimited string to a stored procedure that is composed by empId|ProductId + a comma as delimiter with the purpose of filling a link table. using SQL Server 2008 EmployeeOrderLink Table to be filled EmpId OrderId ProductId Example of a possible key MyKeyIds="EmpId|ProductId, EG 2232|33,45...

Best architecture for a 30 + hour query

I have an interesting problem to solve. One of my clients has me developing a stock analysis program with close to 50 years of stock data for almost a thousand symbols. I've developed a series of filters that are applied on any given day to see if anything falls out for a trade. We want to run this filter for each day of data we have ...

adding a calculated/virtual column to an existing query

My query returns a sales column total for each month and a purchases total for each month, for certain categories. SELECT theMonth, sum(Sales) as sumSales, sum(Saleswotax) as sumSaleswotax, sum(Purchases) as sumPurchases, sum(Purchaseswotax) as sumPurchaseswotax FROM ( SELECT date_format(saledate, '%Y-%...

MYSQL select statement conditions

query: SELECT u.deviceID, u.userName, u.contactNo, u.rating FROM User u INNER JOIN TaxiQuery t ON u.deviceID = t.seat1 OR u.deviceID = t.seat2 OR u.deviceID = t.seat3 OR u.deviceID = t.seat4 WHERE t.queryID = 3; +--------------------------------------+---------...

Grouping fields by category and arranging by date, and calculating from another table

I have a products table, with the fields product, category and cost, of type varchar, varchar and decimal. I then have a sales table, with the fields client, productname, quantity, cost, and saledate, of type varchar, varchar, int, decimal and date. I also have a purchases table, with the fields purchasedate, cost, quantity and purchas...

Outputting the name of the month instead of the number

I have a query which returns 3 fields, one of which is the month as a two digit number. I want to basically have it so if month == 1 output january, if month == 02 output febuary etc This is what I am trying, but this does not work at all, and prevent the entire column from being displayed in PHP. while ($row = mysql_fetch...

SQL - displaying zero results

I am looking to display a 'O' or 'No results found' when no records are found based off my query but can't get it right. I think the problem comes from that I am trying to display information about the records I am counting along with how many there are that fit the criteria. Perhaps its not the count that I need to change with ISNULL ...

How do I add Hours, mins, seconds to dateadd sql?

Hi I want to get an entire date So today would be 7/7/2010 12:00:00 am to 7/7/2010 11:59:59 pm So that should be the full 24 hours since 12:00:00 am would be the 8th then. So I have this select DATEADD(??, ??, DATEDIFF(dd, 0, GETUTCDATE())) How do I make it add 23 hours 59mins and 59seconds to it? ...

SQL Function Help

I am trying to archive a datagrid into a datatable so I can find it in the table by the archive date. I am using an INSERT SQL statement as follows: INSERT INTO [VendorArchive] ([Booth], [Deposit], [Rent], [Electric], [Security], [AmountPaid], [DatePaid], [PeriodPaid], [TotalDue], [Notes], [ArchiveDate], [BalanceDue], GETDATE()); SEL...

SQL select / group

I am a student this is homework. I'm getting tired and confused. Any advice will be appreciated. I have two tables. Employee has the following columns: Last_name First_name Address Phone Job_title(FK) Wage Job_title has job_title(PK) EEO classification Job_description Exempt_Non_Exempt I need to select the employees’ last ...

How can I check if a sql query is deterministic?

What I mean by deterministic is that the query will always return exactly the same result set. Is there a way to do this? ...

How to improve SQL Server query containing nested sub query

I was given this SQL query by my boss and told to improve/optimize it DECLARE @pol_0 int, @pol_1 int, @pol_2 int, @pol_3 int, @pol_4 int, @pol_5plus int, @peril_0 int, @peril_1 int, @peril_2 int, @peril_3 int, @peril_4 int, @peril_5plus int, @loc_1 int, @loc_2_10 int, @loc_11_100 int, @loc_101_1000 int, @loc_1001_5000 int, @loc_...

Does SQL Server support the Oracle-like WITH clause?

I've seen mention of the Oracle WITH clause a few times around here for aliasing a subquery like this: WITH myData AS (SELECT id, text FROM SomeTable) SELECT myData from SomeOtherTable Does any version of SQL Server support this? If not, is there a particular reason they don't? Performance? Potential for incorrect usage? ...

Database Custom Profiler FOr .Net or Java

Microsoft provided us a way to create our own profiler by using Microsft.* namespaces. I can trace all queries going to any MS SQL instance. I need to do this on MySQL as well. Is there any api available for .net or java to do this? If anyone can provide also a working code is very much appreciated thanks alot. ...

Change two rows simultaniously

Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008 I'm working on a game fan site. I have a table as follows: ToonId int (primary key) RealmId (FK into Realms table) OwnerId int (FK into Users table) ToonName nvarchar(50) IsMain bit That is a single user may own multiple toons on multiple realms (aka servers), but ex...

Why is my cursor infinitely looping on the last row

Hello I've been trying to use a cursor with embedded sql in c but I can't seem to get it to stop reading the last row in my table. The table is called publication with two attributes pubid and title. I just want my cursor to iterate through and display the pubid. This is what i have: EXEC SQL DECLARE C1 CURSOR FOR SELECT pubid FRO...

SQL Server Agent Job - where to find Package Source

Hi all, I am trying to figure out where an SSIS package is located for a SQL Server Agent Job. I have had to take over the administration with limited knowledge of SQL Server so please excuse my ignorance. I see two Jobs under SQL Server Agent Job in Object Explorer. When I right click on one of them and select Properties, under Job Pro...