i have table: id timestamp 1 31.10.2020 16:32:11 2 09.09.2020 09:15:49 3 22.04.2020 02:48:15 Table have huge amount these data. Column timestamp is data type “nvarchar”. And i …
Tag: sql-server-2012
Extract first argue from column with T-SQL
I need to extract the first argument: “PATHTOPACKAGE” from the string below: which is a column stored at SQL Server msdb.sysjobsteps.command Is there a way to do it by using Regex or Spliting it by blank spaces? Answer Based on the one example we have, a couple of CHARINDEXs a little bit of simple string manipulation gets the job done:
The multi-part identifier “t7.rate_buy” could not be bound
Please help me on this error message: The multi-part identifier “t7.rate_buy” could not be bound. I can’t find how to fix this. I use SQL Server 2012 and I have tried everything but I can’…
How to find Max value in a column in SQL Server 2012
I want to find the max value in a column Above is my table structure. I just want to find the max total value only from the table. In that four row ID 1 and 2 have same value in CName but total val and PName has different values. What I am expecting is have to find the max value
How to update status for part with nothing data when this part is missed?
I work with SQL Server 2012 and have an issue: I can’t update status with No data returned where no result returned from select statement cross apply function. Meaning where no data returned when join parts and company to function then update status to this part with nothing data for that part when data is missing. When I run a
Count times date occurs between two dates in a second table
I have two tables [Charges] and [Defects] and want to produce [Desired Query Output] where the output counts the occurrances of defect when [Charges].ChargeDate is between (and including) [Defects].OpenDate and [Defects].CloseDate. For [Defects] table, a close date of NULL means it has not closed yet. Seems simple enough, but I haven’t found a good example of how to do this.
Does having two or more calls to scope_identity() in a single procedure work?
Does having 2 or more calls to scope_identity() in a single procedure work? For example: For sure @id_1 gets the last inserted id of table_1. The question is, does @id_2 get the last inserted id of table_2? Answer Yes, sure – if both table_1 and table_2 for an identity column – why not?? But please use this syntax: No need
SQL Query Performance Enhancement on NOT IN
Suppose I have a query need to lookup users who bought book A but not bought book B. Typical SQL query can be: This not in query looks not efficient, any enhancement I can do this query? Answer Try using exists clause instead of IN clause – Apart from this you my try having index on below columns –
Find a string inside a string and update in SQL Server
I have a table like this : I need to replace the string inside the tag c24 tag.. Excepted output: I need to replace the letter ‘G’ to be replaced with ‘T’ like this inside c24 tag – HT0010001 and all the rest should be same unchanged… What I tired: Answer If the code always begins with ‘H’, then I
Update column data using SQL query
In our SQL Server database, we are trying to update the old column data in a table. In a table there is lot of data similar to Agency Administrator. This is data is in old format where we were taking single values in a column. Now, due to an update in data structure, we are storing the data as [“Agency