In the following code Combined table still pops up with Nulls. Questions: Why? Is it because of the WHERE statement? Is it only acceptable to use fully qualified names such as Things I’ve tried..different naming conventions and syntax, etc. The fully qualified names version works as expected, hence the …
Tag: sql-server
Update Text Field on Multiple Rows Using Current Text In Field SQL
I have a table with a text field that imported with incorrect characters delimited by a space. Expected Output I need to run an update to remove all the text AFTER the space on a specific number of rows. I figured out a way to select the correct text, but I’m stuck on how to update in bulk. Will return
Issue connecting to SQL Server via Python pyodbc
I have an ongoing issue that I just can’t solve. It concerns a Python script that loads data into a SQL server database. When I run it from my local machine it works fine, however when I run the same script from a server I get the following error: conn = pyodbc.connect(r’Driver={SQL Server};’…
Extract number before and after character
I need to extract a certain number from my ‘TblA’ from column ‘Input’ in sql. I have the following example input and desired output 1 and 2. Input Desired Output 1 Desired Output 2 20 x 88 nc. 20 88 100 x 300 nc 100 300 200x 88 nc. 200 88 5x 300 nc 5 300 ol (200x 88nc.) 200
a query that sum the count of a row from multiple columns in SQL
I have to write a query that sum the count of a row from multiple columns My code is like this, but total doesn’t work: input: output: Answer Use coalesce as follows:
Sql server not updating records with nested case statement in a query
I’m using sql server 2012 and here is my query: it isn’t update my table just results couldn’t configure the issue even i tried a single query just like is there something which I’m doing wrong? or any other way to achieve my desired result? Answer is mandatory to write WHERE Column11 …
SQL Server: update rows that take part in grouping
I’m using SQL Server 2017 (v14.0). I have two tables with one-to-many relationship. I need to group the rows in the “Orders” table and by this info create the row in the “Transactions” table, then I need set the relationship – for a created transaction I need set the Transa…
Issue with SQL Server select statement
I need help with a select statement that I’m currently struggling with. The scenario is this: select * from mytable WHERE isActive=1 and if only id is provided, select everything where the id=@id if firstname and lastname is provided, then select everything where firstname=@firstname and lastname=@lastn…
How can I select the max counted values from that was ‘GROUP BY’ twice?
Sorry for the bad title, I need to improve on how to explain my problem better, obviously. I’m practicing queries on the Adventure Works data in SQL server, and I queried such as: Which gives: And I’m trying to only get the largest count item, expected output looks like this: The max count for eac…
Copying data from rows in the same table if it meets multiple conditions
I have a table that looks this ID C1 C2 C3 C4 Date 101 1 1 1 1 01/01/2020 101 1 1 2 2 01/03/2020 101 1 2 3 01/05/2020 101 2 3 4 3 01/07/2020 201 1 1 1 1 02/02/2020 201 1 1 2 2 02/04/2020 201 1 2 3 02/06/2020 201 2 3 4 3 02/08/2020 What