I need to select a random amount of rows but also ensure that the rows don’t contain duplicate Image values: ImgID Image 1637 PM1371564839.jpg 1638 PM1371564839.jpg 1639 …
Tag: sql-server
Multiple OUTPUT clauses in MERGE/INSERT/DELETE SQL commands?
I have a T-SQL script that implements some synchronization logic using OUTPUT clause in MERGEs and INSERTs. Now I am adding a logging layer over it and I would like to add a second OUTPUT clause to …
LINQ to SQL, select from an inheritted class
Using LINQ to SQL and Object Relational Designing; Let’s say we have a class Animal with two inherited classes, named Cat and Dog. We can load the “Animal” class and its properties easily: However, when trying to load Cat or Dog, dataContext has the attribute of neither Cats nor Dogs. How is…
SQL query to find the highest paid salary for each lanauges
As I am not expert in writing the SQL queries so want for help. I have a table called programmer whose structure & data look like: In prof1 data are: PASCAL,CLIPPER,COBOL,CPP,COBOL,PASCAL,ASSEMBLY,PASCAL,BASIC,C,PASCAL,FOXPRO. In prof2 data are: BASIC,COBOL,DBASE,DBASE,ORACLE,DBASE,CLIPPER,C,DBASE,COBOL,A…
Insert datetime from C# into SQL Server database
when I try to insert datetime value into a SQL Server database I get this error: Conversion failed when converting date and/or time from character string Code: Table table has 1 datetime column called time. Edit: my table created in msSQL 2012: http://i.imgur.com/TJ3t3y7.png my real code is: Answer The actual…
How can I delete using INNER JOIN with SQL Server?
I want to delete using INNER JOIN in SQL Server 2008. But I get this error: Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword ‘INNER’. My code: Answer You need to specify what table you are deleting from. Here is a version with an alias:
SQL “between” not inclusive
I have a query like this: But this gives no results even though there is data on the 1st. created_at looks like 2013-05-01 22:25:19, I suspect it has to do with the time? How could this be resolved? It works just fine if I do larger date ranges, but it should (inclusive) work with a single date too. Answer It
How to select distinct year from a datetime column and add the result to a comboBox in C#?
I am using visual studio 2010 and SQL Management Studio R2 Although the sql query works fine in sql management studio. Its throws an exception in visual studio. Out of index exception whem i edit to make any other adjustments it throws Out of format exception. Please Help me. The code is as follows: Answer Yo…
REGEXP_LIKE conversion in SQL Server T-SQL
I have come across this line in an old report that needs converting to SQL Server. examCodes being the source and learner_code being the pattern. I know that SQL Server doesn’t have REGEXP_LIKE and most places tell you to use PATINDEX. Here’s me thinking that this would work: But I get the error: …
Using field in CASE without group by
I have the following code and I am having trouble figuring out how to NOT include these into the group by. Some of the arguments are purely for the case and that is all. I can’t include them in the group by. I cam’t really group by anything else as I need to get the counts by TransactionTyp only b…