Skip to content
Advertisement

Tag: tsql

SQL Server ‘AS’ alias unexpected syntax

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

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

Advertisement