Can someone explain why do I get an error when executing the following simple query with pandas: import pyodbc import pandas as pd connstr = ‘Driver={SQL Server}; Server=sr1; Database=db’ conn = …
Tag: sql-server
SUM over datedifference?
Lets say I have the following records with column datetime dtTime quantity 2020-12-10 19:21:52.293 1 2020-12-10 19:21:52.323 2 2020-12-10 19:21:53.293 1 2020-12-10 19:21:58.293 1 2020-12-10 19:…
Replace the default clustered index with a non-primary/non-key attribute
I have a request to replace the default clustered index with a non-primary attribute and I have an idea of how to simply drop an index and just make another one but I have no clue how to replace the default clustered index. This is as far as I got. However whenever I execute this piece of code I get
How to identify entries where a data does not exist in a table with a condition
I would like to pull all data where the Article exist in Table 1 but not in Table 2 when the CnTy is PB00. So if the article exist in Table 2 for other CnTy that is NOT PB00, I still want it on the report. I’ve been using a where CnTY != ‘PB00’ and it just filters out PB00
Select only the records with same values
I am working on a SQL statement that will become a part of a view. What I need is to extract only the records that have the same unique key twice. The query looks like below right now. The result I get from the query above is: I need to modify the SQL statement so that the end result is
Add and update a column with sequential numbering based on grouping
I have a table with following structure Id Division Details 1 A some text 2 A some text 3 B some text 4 B some text 5 B some text I need to add a new column of integer type named “Order” with some data as described below: Id Division Details Order 1 A some text 1 2 A some
how to filter data using qualify row_number in sql server [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I am trying to use QUALIFY to filter the data without seccess (in SQL SERVER) also, I do not…
Insert into a table in another database after first deleting
I have two databases that have same tables on those. First I had to delete all the data in employee_table in Database_1. Then after that I need to insert data in the employee_table in Database_2 to the employee_table in the Database_1. I am using SQL Server Management Studio 2017. Is there any solution for th…
Conditional Inner Join with two Functions
I have two functions. I need to decide whether to join with these two based on a BIT Value. Basically if BIT=0 join with function 1 else join with function 2 I tried putting an IF Clause .. but it does not seem to work. What is the proper way to do it? Answer Just add your static condition as
Conversion failed when converting the nvarchar value ‘$28,926.25’ to data type int
Full error message Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the nvarchar value ‘$28,926.25’ to data type int. Answer Something to understand when programming on almost ANY platform is converting between number values like 123.45 and string or text values like “123…