In LINQ-to-Entities you can query entities by doing: I know that behind the scenes it will be translated to SQL to something similar to: However is there a difference (with respect to performance) if I write: Will it be translated to the same SQL query? From my understanding .Where() will return IEnumerable&l…
Tag: sql
Can I use VARCHAR as the PRIMARY KEY?
I have a table for storing coupons/discounts, and I want to use the coupon_code column as the primary key, which is a VARCHAR. My rationale is that, each coupon will have a unique code, and the only commands I will be running are SELECT … FROM … WHERE coupon_code=’..’ I won’t be …
SQL – Select records for the same day between particular data range [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Questions concerning problems with code you’ve written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance. Closed 8 years ag…
Replace Parameters in SQL query text with XXXXX
I m writing a small utility that captures and logs SQL statements, but will have to remove sensitive data from the Query text and replace with with some dummy text (i.e:XXXXX). What is a good way to parse the SQL query in java and replace parameters value? for example: replace with Answer Using JSQLParser (V0…
SQL use CASE statement in WHERE IN clause
Is it posible to use case in where in clause? Something like this: DECLARE @Status VARCHAR(50); SET @Status=’published’; SELECT * FROM Product P WHERE P.Status IN (CASE WHEN @Status=’…
SQL Split Function and Ordering Issue?
I have the following Split function, When I write, This will give me, I need to maintain the order. Answer A simpler function: Sample usage: Or to return orders from a table ordered by input:
Handling Null in Greatest function in Oracle
I want to compare two dates from two columns and get the greatest and then compare against a date value. The two column can hold NULL values too. For example I want the below OUTPUT. How do I use the greatest function or if there is anything else? I am again using the output to compare against another date. A…
Fire a trigger after the update of specific columns in MySQL
In MySQL, I want to fire a trigger after the update of specific columns. I know how to do it in Oracle and DB2: CREATE TRIGGER myTrigger AFTER UPDATE of myColumn1,myColumn2 … ON myTable FOR EACH …
Insert multiple rows in one table based on number in another table
I am creating a database for the first time using Postgres 9.3 on MacOSX. Let’s say I have table A and B. A starts off as empty and B as filled. I would like the number of entries in column all_names in table B to equal the number for each names in table A like table B below. Thus names
Unpivot with column name
I have a table StudentMarks with columns Name, Maths, Science, English. Data is like I want to get it arranged like the following: With unpivot I am able to get Name, Marks properly, but not able to get the column name in the source table to the Subject column in the desired result set. How can I achieve this…