I’m not sure what should I write in the following SQL query to show ‘date’ column like this: “month-year” – “9-2011”. So, what I want to do is to change the data from the first column to show month and year instead of showing month only. Answer Or as @40-Love mentioned you can cast with leading zeroes:
Tag: sql-server
Calculate business hours between two dates
How can I calculate business hours between two dates? For example we have two dates; 01/01/2010 15:00 and 04/01/2010 12:00 And we have working hours 09:00 to 17:00 in weekdays How can I calculate …
Eliminate and reduce overlapping date ranges
I have a set of date ranges consisting of both partially and fully overlapping dates, like this: Using T-SQL, I would like to create a new set of data, per user, with eliminated overlapping data, extending ranges and removing redundant data where needed, resulting in something like this: Cursors are fine if needed, but if I can do without them
Optimizing SELECT COUNT to EXISTS
I have a query to find certain customers from a table. There is an index on customerid, so the DB scans all rows with customerid = 22. Since the result is processed by checking whether the count returns zero or more than zero, how can I optimize the query? I.e. such that at the first customer row with amount <>
DISTINCT for only one column
Let’s say I have the following query. How can I modify it so that it returns no duplicate Emails? In other words, when several rows contain the same email, I want the results to include only one of those rows (preferably the last one). Duplicates in other columns should be allowed. Clauses like DISTINCT and GROUP BY appear to work
SQL and escaped XML data
I have a table with a mix of escaped and non-escaped XML. Of course, the data I need is escaped. For example, I have:
How to sort Varchar Date in SQL Server 2000
My table schema (table Name Stock) Field Date Datetime If Date having datatype is Datetime then SQL Server sorts the date in well/perfect order. See Below Example. select date from stock order by …
SQL Server VARBINARY(max) to c# byte[]
I am querying the table (one of the columns is a VARBINARY(MAX)) which returns some records. Then I save that as .dat.csv then I parse through that .dat file and get that varbinary value into a string by splitting the file based on commas. Now I need to convert this varbinary to byte array. How can I do that? Answer
Null Calculation With SQL Select Statement
I have Following Table Input Output ——————————— 12.22 2.22 If I pass Following Sql Statement: Select Input,Output,Balance=sum(Input – …
CASE Statement in SQL
just a curious question. I have written following code using CASE statement but I don’t have data so I am not sure if my logic is correct. All I am doing is I am applying length check on each field …