Get a snapshot on the first day of the month

My dataset looks like this: emplid region location sub_dept dept start_dt end_dt days ------ ------ -------- -------- ---- -------- ---------- ---- 123456 East NY A 1 7/1/2005 9/30/2005 91 123456 East NY B 1 7/1/2012 11/9/2012 131 123456 West San Jos

GROUP BY and SELECT in a SELECT

My problem is solved but now i have a few performance questions. I want an overview of my caught pokemon for all editions, it works as far as i tried, but i don't think it's best practice. select #p.idpokemons as ID, #p.name as Pokemon, #t.name as Tr

Select different channels in the same row

I have a table called "character_certifications" where I need to select different strings as count in the same result. The table looks like this: classId charId var 0 268482320 EmergentAbility65-1 0 268482320 EmergentAbility65-2 0 268482320 Emer

Order by custom value in wordpress

I Have this data: id meta_key meta_value 1 d_t_w 4 weeks 2 d_t_w 2 Days 3 d_t_w 3 Weeks 4 d_t_w 4 Days 5 d_t_w 1 Week WP query: $query['orderby'] = 'd_t_w'; $query['order'] = ASC; $query = new WP_Query($query); The Result: id meta_key meta_value 5 d_

SQL Query - Hide Lines

in my environment we use Altiris to control our asset and daily we had a policy that set status retired to computers that stay more than 45 days offline and turn back to active if this computer appers online on network. The problem is sometimes (not

How to use escape with LIKE in SQL Query

My Query is : declare @param1 INT, @param2 nvarchar(max) set @param1 = 1 set @param2 = '[Test_data_forQry],[Next_Test_Data]' SELECT * FROM Table1 WHERE ColumnA = @param1 AND (',' + @param2 +',' LIKE '%,' + CONVERT(VARCHAR, ColumnB) + ',%'); The squar

Get the missing sql number

In table i have field pwd which goes like this 001 , 002, 003 , 004 . To get highest value of that i go like this ("SELECT pwd FROM users WHERE pwd= (SELECT max(pwd) FROM users)") That way i got number 004. To increment it and add again to table

separate sql lines

I am trying to join two rows and get the address for only the rows that are contained in the first but I cannot get the values to tally. I have the following query it results in a total of 55,059 records: SELECT AccountID, AccountParameter1 FROM Acco

Find an SQL function from a SQL statement in C # using regex

I want to parse a SQL statement which may use a SQL function inside the query text. Now using C# regex I'd like to parse the string and check if there is any function name(s) used inside the query and extract those. There may be multiple functions us

Select the instruction in the decode function

so I am writing a select query using a decode function, and set the result into a variable. The thing is, when there is no lines, I always got no result error. I tried decode with the value, and counting, but no results. SELECT decode(count(id), 0, (

how to combine two sets of results without null

I have two result sets that I would like to combine , since I would like to send them as a dataset to my ssrs report. I am currently doing : Select Sum(Teamsales) as TS, Null as PS from ABC; union Select null as TS, Sum(ProdSales) From DEF; I get an

SQL ORDER BY Idea

I have two tables. Uploaders - id, name, icon, views Videos - id, uploader, video, views uploader column is used as reference to the uploader of the video. so, I am able to use sum() function to count how many views each user has in total from all of

Name of the mysql query from the list identifier

i have a little problem here... let me explain.. lets say i have a table like this... Barang ╔══════════╦════════════╦════════════╗ ║ IDBARANG ║ NAMA ║ IDKATEGORI ║ ╠══════════╬════════════╬════════════╣ ║ 1 ║ Ban Becak ║ 1,3 ║ ║ 2 ║ Velg Becak ║ 2,4

Understand the relationship between UNION and ORDER BY?

Here are 2 queries - select * --1 from Employee --2 where HireDate < '7/1/2001' --3 order by HireDate --4 --5 gap select top(2) * --6 from Employee --7 where HireDate >= '7/1/2001' --8 order by HireDate --9 I want to do a UNION on them. When i put U

SELECT ONE Row with the MAX () value on a column

I have a pretty simple dataset of monthly newsletters: id | Name | PublishDate | IsActive 1 | Newsletter 1 | 10/15/2012 | 1 2 | Newsletter 2 | 11/06/2012 | 1 3 | Newsletter 3 | 12/15/2012 | 0 4 | Newsletter 4 | 1/19/2012 | 0 and etc. The PublishDate

Link multiple tables in a database

I have actually this little function working as supposed: Function createAttached(strTable As String, strPath As String, strBaseTable As String) As Boolean On Error GoTo CreateAttachedError Dim tdf As TableDef Dim strConnect As String Dim fRetval As

Optimization of the MySQL query LEFT JOIN

My goal is to select articles where the primary_category_id (articles table) or any of the secondary categories (articles_secondary_categories join table) are a given value. In this example query, category 1. I tried using other types of joins but th

Adding multiple tables to the MySQL database using PhpMyAdmin

I have created a form and from the form fields I have created a sql file that I am going to use to create all the database fields for the form in my mysql database. I am using type following code to create the entries with : ALTER TABLE `rok5g_chrono

Attach tables by appropriate period

In a postgresql database I have 2 tables like these ones: Table items: item_id item save_date (date dd/mm/yy) ---------------------------------------------- 1 car 01/12/11 2 wheel 10/12/11 3 screen 11/12/11 4 table 15/12/11 Table periods: period_id p

How to find the current database type

We have a single SQL script for execution on multiple types of database. Is it possible to get the type of current database on which SQL script is executing? Note: We can't use non standard SQL i.e . TSQL etc.No, there is nothing in ANSI SQL about de

Emulate behavior similar to REGEXP in SQL

I've posted this question on the new dba.stackexchange.com (please, let me know if I have to delete one). I'm working on a DB2 database, and as far as I can see regexp is not supported (without additional libraries). So I cannot implement something s

Where statement clause repeat the data

I have a database that has been populated with some data using create and insert into statements. I have written a SELECT statement that has a WHERE clause. The problem that I am encountering is that when I run the statement I have found that some of

Using ORDER BY on indexed columns

In SQL Server 2008, let's say I have an index (LastName, FirstName) on the table Employees. The index is sorted ASC on both columns. Is there any point to the ORDER BY in the following query? SELECT LastName, FirstName FROM Employees ORDER BY LastNam

Reverse in Oracle this path z / y / x to x / y / z

How would I do in a SELECT query to reverse this path : z/y/x for x/y/z where / is the delimiter and where there can be many delimiters in a single line ex: select (... z/y/x/w/v/u ...) reversed_path from ... The simplest way would probably be to wri