Table1 has 4 columns = Col1 , Col2 , Col3 , Col4 Col1 is id(integer) column = 156 , 159 , 175 Col2 is varchar column = CAA , DFE , EME Col3 is varchar column = 12345 , 23465 , 43122 Col4 is varchar column = 2 , 3 , 6 I am creating a stored procedure which accepts
Tag: sql-server
Calculate conversion rate with the specified conditions
Here is my sample data table: ID Status 1 New 1 Processed 2 New 2 Processed 3 New 3 Processed 4 Processed 5 New What I am trying to solve here is calculate the conversion rate from Status ‘New’ to Status ‘Processed’. From the dataset, only ID no.1,2 and 3 fulfilled the requirements of my problem, and ID no.4 and
Get MIN value between 3 columns on same row
Though I have come up with a couple of working solutions to what I am looking for, I am wondering if there is a more streamlined way of determining which of 3 columns from a single row contains the smallest/min value. Below is an example of the data I am working with: AccountNumber Job DaysSinceLastSale DaysSinceLastCharge DaysSinceEstablished YO502 NULL NULL
Looping through a column to check if a cast succeeds in SQL Server
I am trying to check if an entire column which is varchar and make sure it can be cast to float. I have a cursor portion like so: For some reason, it is always returning 1. I already in a previous part of the cursor (not shown but above), verified that the column passed in (@ColumnName) is NOT NULL at
Can’t connect Sqlalchemy with pyodbc to SQL Server 2000
I followed this website by installing After install I try this code and it worked, it print all records from table2 However, I want to use SQLAlchemy with pyodbc and it does not work ProgrammingError: (pyodbc.ProgrammingError) (‘42000′, “[42000] [FreeTDS][SQL Server]’schema_name’ is not a recognized function name. (195) (SQLExecDirectW)”) [SQL: SELECT schema_name()] (Background on this error at: https://sqlalche.me/e/14/f405) How can I
How to group data by past few weeks?
I have an original table like this, Can I group my data using GROUP BY in SQL to get the aggregate value by each week? My expected output will be like, Answer This is a way of doing it, probably not the best way however. Personally, I feel like this list is not something you’d want to do in SSMS.
How do I do multiple CASE WHEN, using LEAD() to look at an entire row in SQL?
I have a set of data that I need to manually adjust a column (inserting 0) for the row trailing a specific row, based on a record in one specific column. For example: My desired output: TYPE ObjectID DATE AMT1 AMT2 AMT3 AMT4 TOTAL AMT C 1234 3/1 2 0 2 2 4 A 1234 3/2 5 0 0 0
Find ID which doesn’t exist from another table
I am studying SQL and I am not sure which is the way to filtering data. For example, there I have two tables: Reference_OrderTable: OrderID Item Price OrderTable: OrderID Item Price Reference_Ordertable: this table has all the type of orders. OrderTable: this is the actual order table, we store by customer’s orders. I am looking for missing orderID in OrderTable.
BCP queryout hangs with READ COMMITTED transaction isolation
Using SQL Server 2016 and bcp version 14 My query returns about 16k rows and runs quickly to completion in SSMS with the default (READ COMMITTED) isolation level however if I try to save the output of the same query using BCP the tool hangs. If I set isolation level to READ UNCOMMITTED in the BCP query then it completes
How to use group by with case statement [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 8 months ago. Improve this question I have a table with following fields CREATE TABLE Tblstock ( ID int