I have a slight issue retrieving multiple recordsets (with column names) and pasting the data into an Excel sheet, like the image below The VBA code that I have just retrieves the first recordset but …
Tag: sql-server
Get unique values using STRING_AGG in SQL Server
The following query returns the results shown below: SELECT ProjectID, newID.value FROM [dbo].[Data] WITH(NOLOCK) CROSS APPLY STRING_SPLIT([bID],’;’) AS newID WHERE newID….
How to make all combinations with given words in SQL
I’ll make a search query that search on each individual word contains in my table using SQL Server. The query must work as following situation: The query must search in the colour, style, marerial and shape field like an or operator The query must search on each individual search word (like blue, red, m…
insert xml data to table stored procedure sql server
I have xml in following format I want to insert them in table so the table should have 4 records in the example. columns are name and alias. How can I achive this using cursor or something else? What i have tried. In cursor for entity i try insert alias value,but only first alias is taken. Answer
Correct use of Try Catch for the SQL connection in C#
Is this code correct in means of Try/Catch? I need to value whether the action is done or not to inform the user about the result, so I will then get the bool value to know if connection was successful. Answer Your method can actually have 3 outcomes: The table was created successfully (method returns true) T…
VIEW – INDEX SQL SERVEr
Does anyone know another way to run the query below more efficiently? I’m using SQL Server 2014. I’m facing a problem if i create index on table or on view . On table 2 (TB_FATURA_ITEM_TRANSACAO_HST) , has stored 50 million rows . I was wondering using Schemabiding on View , but I was looking in s…
Saving a pem certificate in a SQL Server database
I need to save the content of a *.PEM certificate in a SQL Server database. I plan to save it in a nvarchar() column, but I’m not sure what length should I use. I would appreciate any advice. If you have experience with saving pem files to a relational database that would be even better. Answer There is…
Adding a new column with data
Below is my table: Now I want to add a new column called ‘Gender’ with values M,M,M,F in 4 rows respectively. I first added a new column using: Now I understand I can add data one by one by using: But how do I add all 4 data at once? Answer You don’t, unless there is some other piece of
How to get the return value from EXEC(Query) inside stored procedure
Is there any way to get the return value from the following SQL script? The @ColumnValue will be 1 or 0. I am expecting single value from @ColumnValue. I want to check if the @ColumnValue is NULL or not. If Not Null, I want to update a table with this @ColumnValue. Thanks in advance Answer If you update table…
How to compare two strings based on percent match in SQL
I want to post a solution to a interesting problem I was facing in T-SQL. The problem: Compare two string fields based on a percent match. In addition, the two strings may have the words in them translocated. For example: “Joni Bravo” and “Bravo Joni”. These two strings should return a…