I need to execute a sql query from within a c# class. I have thought of 2 options Starting a process of sqlcmd. Using a SqlCommand object. My question is which would be the better way? It’s important that the solution only holds a connection to the server for a short time. I’m open to other ideas …
Tag: sql
Get the 2 digit year in T-SQL
I need to get the current 2 digit year and increment by one. So the current number I’m looking for should be 11. Probably really simple but I’m a sql noob 🙂 Thanks Answer You can do ( YEAR( GETDATE() ) % 100 ) + 1 See GETDATE & YEAR
How can I round a decimal to the nearest even number in SQL?
I need to round a decimal in a sql query on Oracle 10g to the nearest even number. If the number is even, it should be returned. If the number is odd, the next even number should be returned. This is what I want: 8.05 should return 8.06, 3.48 should return 3.48 How can I do this? Thanks, Andrew Answer
Variable value assignment using RETURNING clause
I try to do this, but it’s a syntax error, what am I doing wrong? my table: Answer You need to use the INTO clause in the RETURNING to set the value being returned into your variable: You also need to specify the data type of your variable; I’m glad to see postgresql supports %TYPE and %ROWTYPE.
SQL query for non duplicate records
I’m attempting to build a query that will return all non duplicate (unique) records in a table. The query will need to use multiple fields to determine if the records are duplicate. For example, if a table has the following fields; PKID, ClientID, Name, AcctNo, OrderDate, Charge, I’d like to use t…
mysql CREATE VIEW not working from mysql_query
I have a code to create VIEW in mysql database which is working fine on my local server. It creates and crop view normally. But on my Online server it gives error for online database I manually create VIEW in Database form PHPmyAdmin [Myadmin is in localhost online] it creating, SO i have permission to create…
How to count one to many relationships
ReporterTbl has a one to many relationship with AttachmentTbl. In ReporterTbl, I have an ID (101) and I can have AttachmentTbl more than one Attachments related with ReporterTbl.Id Basically, what I am trying to know is given ReporterTbl.ID, how many Attachments do I have? Table structure: Answer Note: It is …
Left Outer join and an additional where clause
I have a join on two tables defined as a left outer join so that all records are returned from the left hand table even if they don’t have a record in the right hand table. However I also need to include a where clause on a field from the right-hand table, but…. I still want a row from the
How to search for a substring in SQLite?
Whats the most efficient way to search for a sub string in SQLite? I’m looking at the LIKE operator. Do I have the right idea? Has this worked well for you? http://www.sqlite.org/lang_expr.html …
How come queries aren’t being added to Django’s db.connection.queries in tests?
I’m trying to capture the queries which my code submits to the database by examining the contents of django.db.connection.queries. For some reason though, after all the automatically produced setup queries are logged, no further queries are logged from my own code. The following test case demonstrates t…