Posts

Showing posts with the label SQL

SQL command works from Management Studio but not command line (SqlCmd)

SQL Server has a command line component which allows users to run SQL commands directly or in files from the command line.  The command is sqlcmd (or Invoke-SqlCmd for Powershell). I recently ran into a situation in which my commands would run just fine in SQL Server Management Studio, but failed from the command line.  Specifically, I was running a series of SQL commands stored in files.  I would run the files one after another. What I found is that some of the files were missing the "USE [DatabaseName]" directive.  So, when those files ran, they were not targeting the correct database.  These worked in Management Studio however, because the earlier scripts had the directive, and Management Studio holds onto that setting.  That is, once a script sets the target database, it will use that database until instructed otherwise.  The command line tools do not do this.

SQL Coding Standard

A couple years back, I needed to define a Coding Standard for a development team to use in peer code review.  Finding coding standards for C# was easy.  There were several complete standards available.  I essentially just used the excellent  IDesign Coding Standard  with a couple modifications to fit our group. The search for a SQL Coding Standard however was not quite as straightforward.  I could find only a few people who had written coding standards, and none of them quite covered everything.  So, I wrote/aggregated my own.  I drew from some of the sources I found and added my own thoughts as well. I split the information into a coding convention & style guidelines because I believe that style should not be the focus of peer code reviews.  I have made the resulting Coding Convention & Style Guidelines available on Github.  Direct links are below: Coding Convention & Architecture Guidelines Naming Convention & St...

Working with external databases in ClearSCADA

I've been working with an external SQL database lately & trying to use ClearSCADA to present some data from it.  The hope is to give my users a single login & a cohesive user interface.  I realize ClearSCADA is not designed to be a general front end platform for any database, but given the fact that it offers the ability to query linked tables, I'm trying.  Below is what I've found so far in terms of limitations.  If anyone from Schneider happens across this, it may be good feedback for the developers.  Joins appear to be done in ClearSCADA rather than the RDMS.  This leads to some very inefficient queries.  I've seen one of my queries turned into 20 queries and then joined in ClearSCADA. The Mimic SQL List refreshes every 10 seconds.  Would be quite handy if this could be disabled and refreshed manually (via button or script).  On heavier queries, the page essentially freezes while the query runs. There is no way to get a valu...