Skip to content

Tag: sql-server

Inner Joining three tables

I have three tables I wish to inner join by a common column between them. Say my tables are; TableA TableB TableC I wish to join A-B, but then also B-C all by this common field I will call common. …

How to return default value from SQL query

Is there any easy way to return single scalar or default value if query doesn’t return any row? At this moment I have something like this code example: How to do that in better way without using IF-ELSE? Answer Assuming the name is not nullable and that Id is unique so can match at most one row.

Slow query with where clause

I have following sql query that take only 1 second to execute: But I need a resultset to get the results that has rate greater than 0. So when I change the query to this it takes 7 minutes to execute: Why would this make the query time go up from 1 sec to 7 mins? Since the b table

Retrieving Data from SQL Using pyodbc

I am trying to retrieve data from an SQL server using pyodbc and print it in a table using Python. However, I can only seem to retrieve the column name and the data type and stuff like that, not the actual data values in each row of the column. Basically I am trying to replicate an Excel sheet that retrieves

SQL Server 2012 how do I view data?

I have several tables in my database and I am using the SQL Server Management Studio for the first time. I want to see the data. In an SQLite 3 or MySQL I’d simply type SELECT * FROM tblName WHERE… the output would be in my console. Answer In SSMS open a new query window (Ctrl + n), make sure