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. …
Tag: sql-server
Inserting data into a temporary table
After having created a temporary table and declaring the data types like so; How do I then insert the relevant data which is already held on a physical table within the database? Answer
How to simulate a deadlock in SQL Server in a single process?
Our client side code detects deadlocks, waits for an interval, then retries the request up to 5 times. The retry logic detects the deadlocks based on the error number 1205. My goal is to test both the deadlock retry logic and deadlock handling inside of various stored procedures. I can create a deadlock using…
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.
NULL values are excluded. Why?
This is about a bizarre behaviour I found in Microsoft Sql Server. Please correct me if I’m wrong. SELECT COUNT(*) FROM TABLEA WHERE [Column1] IS NULL; This returns 30018 rows. CREATE VIEW VIEWB …
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
Connecting to SQL Server Express – What is my server name?
I was just given a laptop to perform some development from a client and I am currently in the process of setting it up. Visual Studio 2010 is installed as well as SQL Server Management Studio 2008 R2. I’m trying to open SQL Server Management Studio to connect to the database but so far am not having muc…
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
Add WHERE clauses to SQL dynamically / programmatically
How can I add search condition to SQL Stored Procedure programmatically? In my application(C#) I’m using stored procedure (SQL Server 2008R2) ALTER PROCEDURE [dbo].[PROC001] @userID varchar(20), @…