I have the following SQL table I wrote this code to format result as JSON, but can’t get it in the desired format. If i name all product columns as name then sql returns an error Use different names and aliases for each column in SELECT list. Sql code: Current output: Desired output: Answer You may try …
Tag: sql-server
How to increment date using previous value from same column and skip weekend date?
I have tried to increment date based on other date column and skip weekend date. I know how to check weekend and how to skip date but I want to result as look like below EX. If I will input date in one column like then I want result in new column like NOTE: don’t skip any row from input
Get the max date time in a table with multiple entries for each date
I have a table that has Location | IsBroken | Date AZ 1 2019-01-01 12:00 CA 0 2019-01-01 12:00 NY 1 2019-01-01 12:00 AZ 1 2019-01-…
SQL Table Valued Function – Return certain data from ‘WITH’ based on parameter value
I am trying to do a “with” to loop through some data (which its doing fine). But after that with, I want to return data dependent on a bit parameter. Its important that this is inside a function. …
How to group records by hours considering start date and end date
I’m trying to group records by hours with consideration of duration. Assume there are long running processes and there is log data when process has been started and finished. I’m trying to get report by hours how many processes were running The data looks like this Process_name Start End ‘A&…
Invalid object name of stored procedure error
I have a stored procedure such as below : when I execute this procedure, I get an error: Invalid object name ‘dbo.sp_InsertPumpsStatus’ What is problem? Answer In your script, It can be clearly seen that, You are giving same name to the stored procedure as the table in statement. Make sure the def…
TypeError: Params must be in a list, tuple, or Row in Python
I built out a python script the retrieves data from Auth0 and publish it to Ms-sql but im getting errors When I did the print statements, everything printed great. but when i used SQL commands to try to populate my table, it returns this error Any suggestions/insights appreciated! Answer executemany executes …
SQL Exist in either TableA or TableB
I am attempting to create a script which needs a clause to check of a column value in Table 3 exists in Table 1 or Table 2 Msg 4145, Level 15, State 1, Line 44 An expression of non-boolean type specified in a context where a condition is expected, near ‘)’. Answer Problems with your query: Missing…
Is there a way to add variable value for new column in Alter Table statement?
DECLARE @VName VARCHAR(8) SET @VNAme = ( SELECT TOP 1 xyz FROM table WHERE abc = something ) …
Select multiple values from a single underlying values as a table
I have a table from which I select multiple values based on two underlying values in the table select (1.2 + ca.MaxReturn), (1.0 + ca.MaxReturn), (1.0 + ca.MaxReturn * 0.50), (1….