Skip to content

Tag: sql

SQL/C# – Best method for executing a query

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 …

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

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