Skip to content
Advertisement

Tag: tsql

selecting max value from table with two variable colums (microsoft SQL)

i´m working with a table that looks like this: Start https://i.stack.imgur.com/uibc3.png My desired result would look like this: Result https://i.stack.imgur.com/v0sic.png So i´m triyng to select the max value from two “combined” colums. If the values are the same amount (Part C), the outcome doesn’t matter. I tried to order the table by max value and then using distinct but the

Migrate columns to JSON in SQL

I have a table (Table A) that looks like this: I want to convert it to a table (Table B) like this How do you insert/transform into a json column? Or do I just have to construct the json string myself? Additionally, does the nullableness of the int columns affect creation? Are clicks for example not included or do they

IIF or case when in window function

I have some timestamps in a table and I want to create a dummy variable (0 or 1) that tests if the row above is equal to the current row, after the timestamps are sorted. I need to do this in different partitions. Is there a window function that can do this in SQL Server? So I know my partition

JOIN with OR condition and use only MIN(Column)

I have two tables. Certain values from table t need to be matched with certain values of table m in order to identify a target value from table m. Table t looks as follows. Table m looks as follows. The logic should be as follows: Column A from table t should be matched with column matchA from table m and

Naming a default constraint

I’m trying to create a default constraint here, but the system is generating a weird name for it. If I want to name it df_MY_TABLE_GUID or something, how could I specify that name be used? Answer Just specify the constraint name with the full syntax, like the UNIQUE in your example: As a matter of routine, I always prefer and

Update table with using NEWID() function

In general, I would update a table randomly like the following scripts. However, I get some issue. It would update more/less then 2 rows. I try execute the following scripts many times for debug. The results are not always only two records. If I remove the order by newid(), the number of output result will be fine. It seems like

Advertisement