Finding Rows That Have The Same Value For A Given Field

So out of all rows that I have in this table I think that there may be two rows that have the same value for a given field. Is there a way to determine which two rows those are? Also, I don’t know what the value would be.

Return Condition from case statement in where clause

By searching a number of SO threads I am unable to write a query which returns the appropriate condition in the where clause. For example I have column Col1 which is int and a variable var1 as varchar now I used below query but it is not working. Where CASE WHEN var1 = ‘1’ THEN […]

Is .sql file different for MySQL and SQL?

I have a .sql file and I want to load it into MySQL database. I don’t know from which database (MySQL or MS-SQL) it was created. Now, I am trying to import that file into MySQL database. It is showing errors while importing and executing that file. Q1. So, my question is whether the .sql […]

Dynamic ORDER BY in stored procedure not working as expected

This is my stored procedure to search a gallery of images uploaded by users: ALTER PROCEDURE dbo.sp_SearchGallery ( @strSearchTerm NVARCHAR(50) = NULL, @strCategory NVARCHAR(50) = NULL, @nUserId INT = NULL, @nSortBy INT = 0, @nSortDesc BIT = 0, @nPage INT = 1, @nPageSize INT = 10 ) AS SET NOCOUNT ON DECLARE @nSortSwitch INT = […]

Distinct query with sum operator not working?

I have a question, I have this query where I’m supposed to pull the totals group by PIX_SKU. My issue here is that is doubling the quantities, any help will be appreciate it. SELECT DISTINCT(A2.PIX_SKU), A2.PIX_DATE, SUM(A1.ID_QTY) AS TOTAL FROM IDCASE00_EXTRACT A1,PX_CLEAN A2 WHERE A1.ID_SKU = A2.PIX_SKU GROUP BY A2.PIX_SKU, A2.PIX_DATE Here is some data […]

Slow but simple Query, how to make it quicker?

I have a database which is 6GB in size, with a multitude of tables however smaller queries seem to have the most problems, and want to know what can be done to optimise them for example there is a Stock, Items and Order Table. The Stock table is the items in stock this has around […]

Python – use cursor to perform SQL query, how do I find out if there were > 0 results from SQL?

I have a python cursor that performs an SQL query, and then it outputs the results to a CSV, row by row: conn_string = “DRIVER={SQL Server};SERVER=sde-db;DATABASE=SDE;READONLY=True” conn_sde = pypyodbc.connect(conn_string) # create connection object cursor = conn_sde.cursor() # create cursor object sql_query = “”” SELECT OBJECTID, Property_Number FROM dbo.PROPERTIES “”” cursor.execute(textwrap.dedent(sql_query)) ## then iterates over cursor […]

Getting All the record of particular month – Building SQL Query

I need some help to build SQL Query. I have table having data like: ID Date Name 1 1/1/2009 a 2 1/2/2009 b 3 1/3/2009 c I need to get result something like… 1 1/1/2009 a 2 1/2/2009 b 3 1/3/2009 c 4 1/4/2009 Null 5 1/5/2009 Null 6 1/6/2009 Null 7 1/7/2009 Null 8 […]

Using functions in SQL Server to do string manipulation

We have a number of stored procedures that will need to perform string manipulation on a column in a table. Can I create a function to do the string manipulation and call it from the SP? If yes, how would I do that? Example: I have a table named ‘Names’ and it it has one […]

if condition in where statement

How do I write a query that if one column value is not null then compare the value with the querystring, else do not compare the column value. for example, I have a tbl1 with programs1 and programs2 two columns, the value in these two columns can be null or with value. I want to […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.