Need help on a DATE query in a SQL server?

I have two tables in SQL Server: EMP On_Vacation with colums EmpId, LeaveType, StartingFrom, EndingTo,RejoiningDate The On_Vacation table stores the information of employees who are on leave. I'm trying to query the table in such a way that my query

MySql Return Distinct Rows order by sno DESC group by column

I have the following mysql table: Here in this table there could be houndred of thousands of rows, in which some may be with the same fir_sno [column No. 2]. My problem is that to select only the distinct rows from this table order by sno desc order.

SQL: cross join query


Convert 31/07/2010 to Date format as 2014-07-31

Is there a function wich can convert a date in format like : 31/07/2014 to a format date like 2014-07-31 I want to do this because in my sql query when i put the date in the format with " / " it doesn't understand te format :/ I have this messag

Convert numeric (contains special characters) to silver

Given declare @text varchar(4) ='3677.98*' , @text2 varchar(4) ='1245367.98%' I want the output as follows: 3,677.98* and 1,245,367.98% I tried below: select convert(varchar,cast(3677.98 as money),1) --output as 3,677.98 If I try select convert(varch

How to select the column name in the select statement

I want to copy/update data from Table A to Table B. Table B has some more additional columns. I have tried the following options. 1) `REPLACE INTO `B` (SHOW FIELDS FROM 'A') SELECT * FROM `A 2) `REPLACE INTO `B` (SELECT `COLUMN_NAME` FROM `INFORMATIO

How to create a database on a google cloud sql instance

How can I use Cloud SQL to create a database? When I use MySQL, I could easily run a sql script to create them on phpMyAdmin. I found a site that advertises that it's possible to run SQL files right on Google Cloud SQL. This is exactly what I want to

MySQL internal binding problem

I'm having a bit of a problem with a MySQL query in my PHP. I'm assuming it's down to a simple syntax issue and am hoping somebody here can help me out. The query is: SELECT * FROM `Threads` INNER JOIN `Categories` WHERE `Threads`.`Category_ID` = `Ca

Find the average rating of each SQL movie

I'm currently taking the online standford class on databases, If you could help me solve this sql problem I would greatly appreciate it. Sorry I'm a complete noob. Table Movie: mID | title | year | director Table Rating rID | mID | stars | ratingDate

union of two select queries with different fields

I have two tables empmaster and allocation. I used union to do sql operation in order to get results from two tables. empmaster has empid and other empdetails. Table allocation contains empid from empmaster as foriegn key another field called per_all

Verification of a calculated value with a case expression

I have a query such as: SELECT *, (A+B) AS TOTALVALUE FROM (SELECT A,B FROM MYTABLE) AS MYTABLE1 How can I use a case...when with the calculated value? For example, if my calculated value is greater than 1 I want it to be 10, otherwise I want it to r

MS Access Distinct Records in the recordset

So, I once again seem to have an issue with MS Access being finicky, although it seems to also be an issue when trying similar queries in SSMS (SQL Server Management Studio). I have a collection of tables, loosely defined as follows: table widget_mfg

How to get the hierarchy level of this query

I am trying to get the hierarchy level of this query. Here is the CTE recursive query WITH CategoryRec AS ( SELECT Id, Parentid, Name FROM dbo.Category UNION ALL SELECT cr.Id, c.Parentid, cr.Name FROM CategoryRec AS cr INNER JOIN dbo.Category AS c ON

Generic viewer for paged SELECT sql queries

I am creating a web page where user can select datasource and execute select statements and see the paginated results in table. Now for pagination i am wrapping queries to get total row count and rownum to fetch a particular block of rows. As we add

SQL query error in Oracle

On Exeuting Following Query: SELECT ID FROM INSTITUTE WHERE MEMBER_ID IN ( SELECT ID FROM MEMBER WHERE ID IN (765,769,753,774,778,779,781,790,799,809, 820,823,855,835,839,842,845,849,850,851) ORDER BY NAME ASC ) I am getting following error: ORA-0090

mysql query for both distinct and sum

I have a mysql fields like this: url_id time_spent ------- ---------- 120 14 120 97 120 14 120 97 I want to display only 14 and 97 based on url_id(DISTINCT). select * from table group by url_id,time_spent

Combining query results from two different tables

First select query Table 1: ID Value 131 ABC 120 DEF Second select query Table 2: ID 120 131 I want to write a single query which will fetch me combining two tables (the required output) ID Value 120 DEF 131 ABC Note: if there is no entry in Table2,

JPA or Hibernate with Oracle table partitions?

I need to use an Entity framework with my application, and I have used table - partitions in Oracle database. With simple JDBC, I am able to select data from a specific partition. But I don't know whether I can do the same with hibernate or Eclipse l

SQL Select Question

I using this in Access 2003. Pardon me if this is in the wrong spot, but I hoped someone could help. I have a table with multiple records that have a text represented date field. The date is in a format like: "06/01/2009" I need to select all th

Problem inserting string or NULL into SQL Server database

I'm having trouble coming up with the proper syntax for allowing either a string or a NULL to be passed to the database. Here's my code: string insertString = String.Format( @"INSERT INTO upload_history (field1, field2, field3) VALUES ('{0}', '{1}',