I’ve come across following T-SQL today: that yields following result: The part that got me confused was d(c) While trying to understand what’s going on I’ve modified T-SQL into: which yields following result: It was clear that d & m are table reference while letters in brackets c & b are reference to columns. I wasn’t able to find relevant
Tag: tsql
Remove String and Symbols
I am trying to create a query to remove some varchar and symbols from a big string, basically a table will have a column with this format(the information comes from an API call): so the requirement is to take the main “column names” from the sample, so at the end the string will be like: this should be dynamic because
Bulk insert csv file with semicolon as delimiter
I’m trying to import data from semicolon separated csv file into a SQL Server database. Here is the table structure The csv file is shown below: There are some columns that I don’t need, so I create a format file to import the data. The format file is shown as below Then I tried both bulk insert and bcp in
Select all groups that contain all specified values in a certain column
Say I have the following table: CaseRef NotificationReason NotificationDate 123 SCHEDULED 2022-01-01 234 SCHEDULED 2022-01-02 312 SCHEDULED 2022-01-01 123 RESCHEDULED 2022-01-02 123 DECIDED 2022-01-03 234 DECIDED 2022-01-02 If I want to return only rows that have a CaseRef that has both a SCHEDULED and a DECIDED value in NotificationReason. CaseRef NotificationReason NotificationDate 234 SCHEDULED 2022-01-02 234 DECIDED 2022-01-02 123 SCHEDULED
SQL: Select MAX value from 2 conditions
I have 1 table and 4 columns. I would like to get max value from visit and spending with use condition as max visit first and max spending second. The result should be shown on the YELLOW highlight on Image above. For my code below. Please help me in a better way to do this. Answer This would be the
Loop through table and update a specific column
I have the following table: Id Category 1 some thing 2 value This table contains a lot of rows and what I’m trying to do is to update all the Category values to change every first letter to caps. For example, some thing should be Some Thing. At the moment this is what I have: But there are two problems,
retrieve different format of date values with time from string (t-sql)
I have a requirement where i have to pull the date/time value from string but the problem is that they can be different formats because of which substring becomes more complicated. Here’s what i came up with but is there any other method where i could simply retreive dates of different format with time and convert them all in single
Find groups containing 6 consecutive 1s in one column
I have a table with 2 columns: val with values: 0 or 1 id with unique identifiers How do I to find id with 6 values = 1 in a row. In the example above: id = 9, id = 10. It is desirable not to use loops (cursors or while), but something like sum(…) over(…). Answer You can use
How to correctly join two tables that each have Start Date and Stop Date columns?
This should be easy, maybe even a duplicate, but neither my brain nor my search engine is being very helpful today. My problem is as below: Given two tables that both have: A start date A stop date A property of an employee. Let’s say Desk Number in table A and Team in table B The employee’s unique ID number.
SQL query to find first six characters of the first name if the name is too short append $
Attached two images the first image is the question second image is the code that which I tried. I am stuck with append $ . I have even added my code T-sql: Answer Just try this: