Skip to content
Advertisement

Tag: tsql

Case statements with Join on lookup

I have a big table with some columns having lookup values. I want to create a description column for each lookup column and populate them with description from lookup table. Here is one example main table id1 id2 id3 1 2 3 1 3 4 look up table code id desc id1 1 id1-desc1 id2 2 id2-desc2 id2 3 id2-desc3

Return first element of each cell

I have a table like this: Id Description Recipient 1 lipsum 35235 2 dolor est 123, 456, 2432 3 Lorem Ipsum 143243, 34, 2344 And I’d like an output like this: Id Description Recipient RecipientId 1 lipsum 35235 35235 2 dolor est 123, 456, 2432 123 3 Lorem Ipsum 143243, 34, 2344 143243 I need to join a table of

Difference between delete statements

vs. Answer The logical conditions of the two statements are different. The first statement will delete any row in TableA if both it’s Field1 and Field2 correspond to the equivalent columns of a row in TableB. The second statement will delete any row in TableA if the value of Field1 exists in Field1 of TableB, and the value of Field2

Best way to filter data for a given range

I need to find Claims from a given table having a procedure code between the range ‘Q5000’ and ‘Q5090’. I am able to write a function for Int codes but am not sure how to best deal with characters range in SQL Server? I can manually write all the codes and filter them but is there any way by which

SQL Where clause order

I have this SQL query: It runs fine and displays the expected result without the WHERE line, but I do need to filter the resultant data as that would imply. The error I’m getting is Invalid Column Name ‘FileCount’ after the WHERE keyword. I’ve been reading around and I can’t find any resources online that include all of the elements

Import specific values from csv files to column of existing table

I am trying to figure out how to create a query/tsql that can import values from csv file to existing table. This is example how few records of csv looks like: And my existing table in SQL Employee table All columns already have values except SupervisorId (supervisorId is a foreign key that points at main key of the same table

How to only run left join when the variable is not null?

I’m trying to simplify my stored procedure and I have one that is only using left join based on the user id that is passed in. If the user id is null, don’t do left join, but if it is null, left join it with another table. How should I re-write it ? Thank you Answer Currently your stored procedure

Advertisement