How to dynamic generate row from max value for example if i am passing max value 7 Store procedure should return value 1 2 3 4 5 6 7 without using loops Answer
Tag: sql-server
Conditional Data Validation In SSIS
I have a situation where table has two main columns DataFieldName & DataFieldValue along with some identifier such as OrderNumber. Now in DataFieldName there is value named as “OrderDate”…
How do I create an automated calculated column?
Help me create a column, that shows the company’s budget. Let’s say we have three tables: Budget, Purchase, and Sale. When we selling products, the budget increases, when buying raw materials, it decreases. That is, automatically when you add a value to these tables, the budget value immediately c…
How to insert into a SQL table column using SELECT query?
I have tables A, B, and C. I want to insert UserRoleName values in table C, into UserRoleName column in table A for the corresponding UserId. UserId in Table A, is a foreign key from Table B. UserRoleId is a foreign key in table B from table C. How can I do that? I tried using this query, But this
Dynamic SQL search improvement
I have this SQL query that I am using for dynamic search in the database: In the database I have e.g.: If I provide the input Microsoft Visio I would like it to list How can I improve my SQL query to achieve this? I have done googling, but haven’t found what I want to do exactly. Answer Either pass
How to ignore the GO statements in IF EXISTS block?
I am trying to execute a script based on IF NOT EXISTS condition. But, the block within BEGIN and END gets executed even if IF NOT EXISTS returns 1. I cannot change statements within BEGIN and END blocks. How to handle this situation? Answer As I mention in the comment, GO is not a Transact-SQL operator, it&#…
SqlBulkCopy error: The locale id ‘0’ of the source column .. and the locale id ‘1033’ of the destination column .. do not match
I know there are similar questions but I still haven’t found the answer to this problem. My setup is the following. Source table: Destination table: SqlBulkCopy call: Working scenario: If my reader executes the query SELECT * FROM BulkTable the sqlBulkCopy works fine. Non-working scenario: this logic mu…
Unpivot Table for Multiple Table
I am facing a problem in Unpivot the table. My table structure is I need to convert this columns into Rows and need output like below Answer I would use apply
SQL Server Update Row where date is not the max date when records are grouped by some ID
I have a table where I account records are loaded daily. If an account comes in to the table and it already exists I keep both records in the database but need to update the record with older …
Calculate time difference between two records and insert into another table if difference is greater than 30 seconds
I have the following table Tran_DeviceAttRec table: I want to select and insert only those fields which time difference is more than 30 second into temp table for example if emp_id 2 punchdate is 2021-02-01 16:52:48.000 and Dev_direction is IN and the same emp_id 2 punchdate is 2021-02-01 16:52:54.000 and Dev…