SSMS 2012: Convert DATETIME to Excel serial number

I can't seem to find an answer to this anywhere --- I want to convert a datetime in SQL to the excel serial number. I'm essentially looking for the DATEVALUE function from excel but for use in SQL Any ideas on how to do this? thanksAssuming the desir

Are these questions identical?

is SELECT a,b FROM foo the same as SELECT a,b FROM foo WHERE a=a and b=b? I am getting different results when I run them. Ultimately, I am trying to set parameters for my SSRS report as : SET @a Varchar (20) DECLEARE @a = Null SET @b Varchar (20) DEC

Looping between different lists in python

I'm trying to pull different data sets from SQL into python using different lists. For example I have the following data: years = [2006, 2007, 2008] 2006 = [A, B, C, D, E] 2007 = [D, E, F, G, H, I, J, K] 2008 = [E, F, G] Then to pull the data in, I'm

Alias ​​column name for use in the CASE statement

I have SQL query as below: SELECT a.ID as AID, a.Amt as AAmt FROM (SELECT ID, CASE WHEN Col1 = 0 THEN SUM (Col2 + Col3) ELSE 0 END AS Amt FROM table1 GROUP BY ID, Amt) AS a I get an error: Invalid column name 'Amt'. (note: this applies to the GROUP B

SQL query to return records

I have two queries in my sp the first query returns values like ID Name Department 1 Sang IT 2 Div IT 3 SS EEE and I have second query which returns value like 1 Sang IT 2 Div IT 4 Pav EEE Now when combining the result i need to get ID Name Departmen

SQL query to display list items

Okay, I am trying to write a query from a poor table structure. Below is something that I want to achieve: Table 1: List of Items T1C1 T1C2 A Fred B Bart C Carl Table 2: Second list of Items T2C1 T2C2 1 Chocolate 2 Cake 3 Pie 4 Fish 5 Pizza Table 3:

Invoking an extended set of SQL from a Rails 4 application

I have a Rails 4 application that I use in conjunction with sidekiq to run asynchronous jobs. One of the jobs I normally run outside of my Rails application is a large set of complex SQL queries that cannot really be modeled by ActiveRecord. The conn

SQL - PreparedStatement - Efficiency - JDBC

Which is a better way to execute queries in JDBC Case 1 sql = "SELECT * FROM TABLE_1 WHERE ID = 1"; conn.prepareStatement(sql); ps.executeQuery(); Case 2 sql = "SELECT * FROM TABLE_1 WHERE ID = ?"; conn.prepareStatement(sql); ps.setInt

Adding a non-unique foreign key constraint in DB2

I have these two (simplified to illustrate the question) tables: create table CASE_INSTANCE (id int not null, stage_id int not null, primary key (id, stage_id)); create table SAMPLE (id int not null, case_id int not null); I want to add a constraint

Query JPQL converted to SQL query

Is it possible to convert JPQL query to SQL and save this query to database? I want to write JPQL queries when developing program. But whet will deploy application to server I need compile querys to native SQL depends on DB.I found the answer for Hib

date of two weeks from the current SQL date

How can I do to extract date after two weeks from current date? Example SELECT blabla FROM table WHERE blabla IN [sysdate + 2 weeks] How about ... ? SELECT blabla FROM table WHERE blabla > SYSDATE AND blabla < SYSDATE +14; This SYSDATE +x means x da

How to query the most recent item in a feed table

There is a table called client_application with data something like this; Id user_id name creationDate --------------------------------------- 1 5 name1 date 2 4 name2 date 3 98 name3 date And also a table called application_status which holds the st

Show SQL data for a specific row on the click

I currently have 2 tables, top and bottom. For the top, there would be rows of data I had called out from my SQL database. As for the bottom, the data is from the same database as the top table, but displaying different fields. The fields are all in

Convert this SQL Count statement to LINQ statement

How would this SQL statement be with LINQ if I use Count? select count(*) from GoalCard where GoalCard.Completed_Date is not null Thanks in advance! Update: I would remove the " too localized " votes, beacuse there are peoples that use google to

SQL to Search Number / Currency Values ​​in DB

I've built a web application that has a small search facility. As part of my search, I offer the users the option to search by dollar amounts. I did some searching around and didn't find any solid examples or advice other than the "LIKE" clause

Does First LEFT JOIN apply to multiple JOINs?

I have a multiple JOIN in the form of SELECT * FROM column1 LEFT JOIN column2 USING(id) JOIN column3 USING(name) JOIN column4 USING(info) WHERE column1.id = 44 If changing the LEFT JOIN to JOIN; for obvious reason, the query will return nothing in th

Multiple deletion operation in a stored procedure

I want to make some tables empty if a stored procedure runs but I couldn't do that. What I did is create proc MakeEmpty () as begin delete from table1 delete from table2 delete from table3 end Use truncate instead and remove the () like this: create

How to insert in a permanent table?

I have the this stored procedure which calls other procedure (this returns some rows of data). In the first procedure I need to insert all those rows into a permanent table and return the contents of this table. I have this, but with a temporary tabl

SQL - Best way to GroupByDay from 6am to 6pm

I need to query a large number of rows (containing a timestamp column) and aggregate the results by day. The trick is I need the aggregate functions to be grouped for each day from 6AM until next day at 6AM, not from midnight to midnight. Obviously,

SQL Server: compare columns in two tables

I've recently done a migration from a really old version of some application to the current version and i faced some problems while migrating databases. I need a query that could help me to compare columns in two tables. I mean not the data in rows,

Can anyone explain why these questions are not identical?

I had am maintaining an query that is as follows: select field_1, field_2 from source_table minus select field_1, field_2 from source_table where status_code in (3, 600); When I looked at this query, I immediately thought, "That's lame. Why not just

help with a simple query

My config table: name | value --------+------ version | 1.5.6 title | test How I try and get it: $getCfg = mysql_query("SELECT * FROM config"); $config = mysql_fetch_assoc($getCfg); echo $config['title']; Equals to: Notice: Undefined index: titl

How to delete a single index referenced by foreign keys?

I have a table, let's call it Users. This table has primary key called Id. Despite having Id as primary key (unique clustered), it has other index (unique nonclustered) on the same column(Id). I would like to drop this constraint, but foreign keys re