I am using SqlKata to creating dynamic SQL queries. I have a list of conditions, stored in my database, which are generated according to my business rules. this is my code sample: var list = new List&…
Tag: sql
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, modern and wood) with all possible combinations
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
Presto – hex string to int
I’m trying to convert hex string (starts with ‘0x’) to it’s integer value using presto. For example 0x100 to 256. My hex string is called msg_id. I tried to use this- But I run into a problem, because from_hex expect even number of hex digits (0100 instead of 100). I decided to try and solve this using an if statement,
SQL If Not Any From Left Join Else Left Join
I the following query and I only want the results from the first left join that returns results for the addresses (add1/2/3). Is it possible, or should I just return it all and filer the results later? For example, if add1 returns 1 address, add2 returns 1 address and add3 returns 3 addresses, I only want the result set from
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) The table already exists
MySQL 8 create new user with password not working
I am using MySQL for several years and the command for the creating the new user till the MySQL 5.x version is as follow: Recently I installed the MySQL 8. In that, this command is not working. It is throwing following error while firing above command: Is there any change of syntax in MySQL 8? What is the correct syntax
Return default rows from a function when first SELECT does not return rows
I have this function http://rextester.com/VIHMIG61446 and I’m looking a way to not repeat the whole query on the if, so I decided to use with as to store the result but it does not work for me http://rextester.com/MVMVA73088 How should I use with as? Answer The if-else logic can be avoided completely. The equivalent result can be written as a
Count number of orders for a variation in Woocommerce
I have figured a way to do this, but I am finding my queries are taking way too long, and the more orders in Woocmmerce, and the more variations we add, the longer the query takes… I would hope there is a way in WC or WP to query just variation ids of an order, but alas, I havent found