245 Answered Questions for the topic SQL

05/08/19

Getting what seems to be incorrect data from GeoNames?

I have a hiking website. I am trying to query for parks big and small around the world where people could potentially go walking or hiking. I was trying to use the GeoNames data and was using... more
Sql

05/07/19

how do I get the average of lookup value from ssrs?

=Lookup(dsc.Value,Dsc.value,Fields!Fmotion.Value,"Stage") I want to get average of that lookup value. How can i write an expression that shows average of that lookup value?
Sql

05/06/19

Adding (Nolock) to all select statements in long running SSRS reports?

We have over 500 SSRS reports, is there a way to add all missing (nolock) in the select statements of each dataset by writing a TSQL script? Thanks.
Sql

05/06/19

What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL?

It seems to me that you can do the same thing in a SQL query using either NOT EXISTS, NOT IN, or LEFT JOIN WHERE IS NULL. For example: SELECT a FROM table1 WHERE a NOT IN (SELECT a FROM... more
Sql

05/06/19

How to check for Is not Null And Is not Empty string in SQL server?

How can we check in a SQL Server `WHERE` condition whether the column is not null and not the empty string (`''`)?
Sql

05/05/19

When to use Common Table Expression (CTE)?

I have begun reading about *Common Table Expression* and cannot think of a use case where I would need to use them. They would seem to be redundant as the same can be done with derived tables. Is... more
Sql

05/04/19

MySQL SELECT only not null values?

Is it possible to do a select statement that takes only NOT NULL values? Right now I am using this: SELECT * FROM table And then I have to filter out the null values with a php loop. Is there... more
Sql

05/02/19

How do I script a drop foreign key constraint command in sql server?

I can drop a table if it exists using the following code but do not know how to do the same with a constraint: IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'TableName') AND... more
Sql

05/01/19

Search text in stored procedure in SQL Server?

I want to search a text from all my database stored procedures. I use the below SQL: SELECT DISTINCT o.name AS Object_Name, o.type_desc FROM sys.sql_modules m INNER JOIN ... more
Sql

05/01/19

In SSRS custom code, can we create a function that call another function?

In the Custom code section, if I defined function 1 first, in the next line, can I define function 2 that calling function 1? If not, how can I get around it?
Sql

04/30/19

Difference between two dates in MySQL?

How to calculate the difference between two dates, in the format `YYYY-MM-DD hh: mm: ss` and to get the result in seconds or milliseconds?
Sql

04/29/19

sql - sum columns from same table having multiple unique ids?

I would like to sum 3 columns from the same table based on three unique id. If id="1" sum(area1) If id="2" sum(area2) if id="3" sum(area3) Table data: id area1 area2 area3 1 10 2 ... more
Sql

04/29/19

How to drop a table if it exists in SQL Server?

The table name is `Scores`. Is it correct to do the following? IF EXISTS(SELECT * FROM dbo.Scores) DROP TABLE dbo.Scores
Sql

04/29/19

Syntax of for-loop in SQL Server?

What is the syntax of a `for` loop in TSQL?
Sql

04/29/19

IF' in 'SELECT' statement - choose output value based on column values?

SELECT id, amount FROM report I need `amount` to be `amount` if `report.type='P'` and `-amount` if `report.type='N'`. How do I add this to the above query?
Sql

04/28/19

IN vs OR in the SQL WHERE Clause?

When dealing with big databases, which performs better, `IN` or `OR` in the SQL `Where`-clause? Is there any difference about the way they are executed?
Sql

04/28/19

Is it possible to GROUP BY multiple columns using MySQL?

Is it possible to `GROUP BY` more than one column in a MySQL `SELECT` query? For example: GROUP BY fV.tier_id AND 'f.form_template_id'
Sql

04/28/19

Altering column size in SQL Server?

How to change the column size of the `salary` column in the `employee` table from `numeric(18,0)` to `numeric(22,5)`
Sql

04/28/19

What is the difference between sql and mysql?

I am new to databases and I was wondering: What is the difference between *SQL* and *MySQL*?
Sql

04/28/19

What is Ad Hoc Query?

I'm reading a book about SQL. In that book there's the term _Ad Hoc Query_, which I don't understand. What exactly is an ad hoc query?
Sql

04/28/19

How to get first character of a string in SQL?

I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any string function in SQL to do this?
Sql

04/28/19

Good reasons NOT to use a relational database?

Can you please point to alternative data storage tools and give good reasons to use them instead of good-old relational databases? In my opinion, most applications rarely use the full power of... more
Sql

04/27/19

Should I use an email address as primary key?

Is email address a bad candidate for primary when compared to auto incrementing numbers? Our web application needs the email address to be unique in the system. So, I thought of using email... more
Sql Sas

04/27/19

Join overlapping date ranges?

I need to join table A and table B to create table C. Table A and Table B store status flags for the IDs. The status flags (A_Flag and B_Flag) can change from time to time, so one ID can contain... more
Sql

04/27/19

Datetime equal or greater than today in MySQL?

What's the best way to do following: SELECT * FROM users WHERE created >= today; Note: created is a datetime field.

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.