Skip to content

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…

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 shou…

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 a…

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