I want to set a default value to a column while declaring a table , but the value is not constant , actually it’s based on some other data from another table . I’m interested to know if there is such …
Tag: sql-server
How to bypass NULL in a Lookup Table using JOIN?
In SQL (SSMS), I am trying to do a lookup using a ranging table (similar to Point_Lookup below) and what I need is to bypass the NULL scenario. Firstly, please use below SQL codes to replicate the …
why does SQL server consider SS as an Umlaut-S (ß)?
When I run the below query: it returns a 6. I specifically chose ß for a function as I thought it very unlikely to appear in any of my data. This was working perfectly fine for several weeks but now all of the sudden it’s detecting ß where there is no ß and therefore screwing up my function. Will someon…
INSERT into table wherever update_time is latest
I have a table that has data about session. I want to insert hardcoded values for every new session row added at the latest time. for example, given this table with 3 session rows information added …
Query won’t convert a nvarchar(30) to a decimal
I have the following query, that when it is run gives the following error: Conversion failed when converting the nvarchar value ‘247.300’ to data type int. The query is as follows: SELECT UD….
SQL Statement // between with datetime
I have following query: select s.ScreenID, s.ScreenName, ps.ScheduleDate from Screens s left join PerformanceSchedules ps on ps.ScreenID = s.ScreenID where s.TheatreID = 2 and ((ps.ScheduleDate not …
SQL join condition either A or B but not both A and B
I have sales data by years and quarters and for the last year I want to fill missing quarters with last available value. Say we have source table: +——+———+——-+——–+ | year | …
TSQL query with aggregated data
I have a query that returns the min, max, avg and total for two different products. The client however wants the min, max, avg and total combined for both products. However I have an undesired result …
Get query results for all date values besides current month
I need to get values for data excluding current month and taking this year into account. What I currently have is the following WHERE 1=1 AND CAST(created_at AS DATE) >= ‘2018-01-01’ AND …
Stored function not returning a table in SQL Server
I’m trying to create a stored function called func_GetMenuItemsForMenu. For this function, I need to pass the ID of the menu to it. The function will find all MenuItems that are on the menu. It will …