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 DaysS…
Converting day datetime to timestamp in Snowflake
I have a datetime data in a table in Snowflake and I want to convert it into a timestamp The output I want is: The methods I tried: etc.. None of the above conversions worked Answer using the correct formatting tokens, your valid datetime strings can be parsed. Depending if you what to have or not have timezo…
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
Return IEnumerable rather IEnumerable
I need to join two tables and get the data from one of the table using linq. The join works fine but it returns IEnumerable <$IEnumerable><$Ojbect> and I need IEnumerable<$Object> Here is the code: Thanks Answer In general, when you want to “flatten” a collection, SelectMany is t…
The LINQ expression could not be translated. Translation of method failed
I want to return list of ItemNos (string), even if few characters match and even if characters match in different place. For eg: If I pass in “appl” or “apole” or “daple”. I want DB to list “apple”. Tried using levenshteinDistance: (Checking for strings with les…
How do I return a table from a function with a bespoke column name?
This function works: But when I try to add some text to the column name: This just fails as a syntax error on $1. Or: select * from a(‘some prefix’) doesn’t work. Is there some other syntax that does the job? Answer That’s simply not possible. SQL does not allow dynamic column names. Y…
How to use Peewee to make CASE SQL queries?
I have a table in postgres that holds a priority integer for each row. The priority needs to update whenever I add a new row or change the priority of an existing one for all of the other rows in the table. One way to do it in pure SQL would be with a CASE query: Question: How can I
PLS-00103 error while executing a sql block (Encountered the symbol “SELECT” …)
I’m trying to learn PLSQL and this is a code that I been trying to execute, When I execute the code I get the following error. I know you can assign a variable to the select statement and use that variable in IF statement, I just want to know the error in the following code. Answer OR with a variable
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’…
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.