Stored procedure has multiple functions. Step One: I need to retrieve an int from a table, SUM it with an @int variable that is user entered. Then store that value back into the same column it was retrieved from. I.E. We have one, we order one, add one because we now have two because that item is already in i…
Tag: sql-server
Full SQL statement logging on Dropwizard
I’ve a Dropwizard application using JDBI and SQL Server. I would like to get all SQL statements logged with their parameters but I don’t seem to be able to. This is what’s usually recommended to do: logging: level: INFO loggers: “org.skife”: TRACE “com.microsoft.sqlserver.j…
Perform same SQL query on multiple databases
I’m trying to adapt an SQL query to check the value present in a certain field that is present in every database on my server. There are 100 individual databases, and I would like to check a specific record of each one. The answer is probably to use a command like the one below, but I’m having dif…
Check if a string contains only number
I am trying to check if a string contains only valid number in the following format But it should reject anything that contains non-numbers including double dots. Here are some invalid formats I have done the following When seems to work except for the case where there is more than one dot in the string. How …
SQL select duplicate rows based on multiple columns
I have created a request that returns me IDs of rows having the same column value. For example : id | Value ______________ 1 | label1 2 | label1 3 | label1 4 | label2 5 | …
Select certain column only if condition met
I want to have a select that will not have fixed number of columns. Column OptionalColumn should be selected only if variable @check = 1 This is what I had (syntax is bad but maybe it explains my problem) It is crucial to have it only if @Check = 1 and not having it if @Check = 0. Is it
Update and insert to one table from another
I have two tables: table1: (ID, Code, Name) table2: (ID, Code, Name) with same columns I want to to insert data from table1 to table2 or update columns if that exists in table2 (table1.ID = table2.ID) What is the simple way to do this? WITH OUT MERGE Answer There are some issues with Merge statement,so it sho…
Select all rows and ignore the first row
I’m currently using the following SQL query which is returning 25 rows. How can I modify it to ignore the first row: I’m using SQL Server 2008. Thanks. Answer You can use EXCEPT in SQL Server 2008. For SQL Server 2012 and above, you can use FETCH OFFSET
Convert iso_week to calendar date in SQL
I’ve been searching though the archives without finding what I am looking for- I’d be happy for some guidance. I have a data set where I want to report aggregated number of appointments by provider (STAFFID) and work week, the latter defined by the week’s Monday date. I’ve played with …
the row values updated or deleted either do not make the row unique or they alter multiple rows
I want to delete row and I get this error: the row values updated or deleted either do not make the row unique or they alter multiple rows Answer There are duplicate rows in your table. When this is the case you cannot edit table using UI. first delete rows with matching data using SQL then try and edit. Dele…