Skip to content

Tag: sql-server

SQL grouping by month and year

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 me…

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…

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?…

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 …