Query Syntax





SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

Share tech news, updates, or what's on your mind.

Sign up to Post


I know that I can source the list of all DB parameters from sys.parameters or sys.all_parameters but I am unable to get the correct default_value. It's always for all the parameters even if they have default value.

Can anyone please suggest what I can do about it.

Free Tool: Port Scanner
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


I am having a few issues getting my SQL statement to work and I am unsure why as it looks ok to me?!?!

Here is the statement:

-- keep the usrprintlog table up to date

INSERT INTO usrUsersPrintLog (UserID)
Values (SELECT UserID FROM ZSD_RFUSERS where NOT EXISTS (Select ZSD_RFUSERS.UserID = usrUsersPrintLog.UserID))

So basically it should insert into 'usrUsersPrintLog' (just the UserID). any entries that are in 'ZSD_RFUSERS' that dont already exist in 'usrUsersPrintLog'.

I'm sure there is a clearer way for me to explain that!! haha

Here is the error:

Hi Team,
   I am not able to install SQL server 2008 R2 in windows 8 machines.If I install the setup file after few seconds automatically closed.Not running What should i do?I was tried 32 bit & 64 bit setup file for installation.Both are not able to install
My Table looks like below

host id       itemname       itemvalue       quantity
1                   A                               10                      1
1                    B                        3                   2
2                    A                         9                       3
2                    C                         40                       4

I have attached my output in image , i have tries with procedure but none seems to be worked out .
I need to convert VBA code that updates or inserts data into a Table to Stored Procedure in MS SQL.  Attahced is a snippnet of the VBA code I need to convert.   Hoping I can get some guidence on what needs to change ( I am sure a lot) but could use some help to get started.
procedure TfrmAdd.BitBtn2Click(Sender: TObject);
  sUserSurname , SUserDOB , sUserID , sUserName , sPassword , sAccessType
 ,sNotes , sEmail , sAllergies , sOccupation , sStaffName , sContact1 , sContact2 , sEmergencyContact : string ;
 iContact1 , iContact2 , iEmergencyContact : integer ;

  sUserName := edtUserName.Text ;
  sUserSurname := edtUserSurname.Text ;
  sUserId := edit1.Text ;
  sStaffName := edtUserName.Text ;
  sPassword := edit2.Text ;
  sAccessType := cbxAccessType.Items[cbxAccessType.ItemIndex] ;
  sContact1 := edtUserContact1.Text ;
  sContact2 := edtUserContact2.Text ;
  sEmergencyContact := edtUserEmergCont.Text;
  sEmail := edtUserContact1.Text + '@' + edtUserContact2.Text ;
  sAllergies := edtUserAllegies.Text ;
  sOccupation := cbxOccupation.Items[cbxOccupation.ItemIndex] ;
  sUserDOB := datetostr(dtpUserDOB.Date) ;

  WIth dmAPMP do

      qryAPMP.SQL.Clear ;
      qryAPMP.SQL.Add('Select * FROM Staff Order By ID') ;
      qryAPMP.SQL.Clear ;

      qryAPMP.SQL.Add('Insert into Staff (ID , [Staff Member Name] , [Staff Member Surname] ,') ;
      qryAPMP.SQL.Add('[Date of Birth] , Occupation , UserName , Password , [Access Type],') ;
      qryAPMP.SQL.Add('[Contact 1] , [Contact 2] , [Emergency Contact] ,') ;
      qryAPMP.SQL.Add('[Email Address] , Allergies )') ;

      qryAPMP.SQL.Add('VALUES (' + QuotedStr(sUserID) + ',' + QuotedStr(sStaffName) + ',' + QuotedStr(sUserSurname)) ;

Open in new window

How to fetch file name, date property in the bulk insert process of SQL?

CREATE TABLE #T (IntCol int, XmlCol xml, filename nvarchar(1000),cr_date datetime);

   BULK 'c:\Testing\Test.xml',  
      select * from #t  

How to fetch the filename and datetime file created?
I'm running a SQL Statement below in SQLPLUS in Oracle. My goal is to join two tables and to output the results to a CSV delimited file. When I export the two tables individually the SQL statement takes about 60 seconds to run. When I join the two tables together by means of the record_id the SQL Statement runs indefinitely and never finishes. Right now it has been running for over 30 hours and has created a 75GB CSV output file on disk and it is still running! What is wrong with my SQL statement? It seems straight forward to me but I must be doing something wrong. Thanks for your help!

set colsep ,;
set echo off;
spool csv_exportoutput_full.csv;
select …
I've created a query with Start Date and End Date parameter so that when someone enters the start date and end date it will extract data in between those dates. Now the extracted data has  2 columns one for reason and the second column for downtime.  I would like to add downtime for same reasons instead of having many rows. I tried using Group By  SUM in the query but is showing an error as a complicated expression; simplify it. Can someone help me with this?
I am looking to create various bar graphs and pie charts on an ASP web page with data from a sql server query.
Free Tool: Site Down Detector
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I'm not sure what I'm asking, so part of my question is to help me understand what I'm talking about. :)

We're trying to import a SQL Server 2008 DB into SQLAzureMW. However, once it imports, I found the "Default Value or Binding" settings for all our tables aren't coming through when those values are (from what I can see) a default value we somehow, and for some reason, created? (Our DB Admin left years ago.)

I can make such dummy "defaults" in SQL Management via commands lines like this...

create default dbo.MyOwnGUID as newid();

After I run that, now if I go into a table's design, select a column, click on "Default Value or Binding", and then click on the dropdown arrow, my new "default" creation of "dbo.MyOwnGUID" is now listed as an option to select.

First question: What exactly are these things called!? Are they just called "defaults"? (At first I thought "default constraints" but that appears to be something else, as they don't appear in sys.default_constraints.)

Second, where can I see a list of all these "defaults" we created in our DB years ago? I'd like to see them graphically in Management Studio, but maybe it's not an option, and it requires SQL.

And third, are these considered good or bad practice? (I only ask because it seems odd they won't import into SQLAzureMW. However, I can save that problem for another post, as I need to first figure out what's going on.)
i have developed application using vb.net. which have sql server 2008 database and also includes crystal reports. and i want to create .exe of project. For distribution. I am trying to do this with visual studio 2010.. Using traditional method..by selecting Setup And Deployment Projects..but after clicking on primary output it give message like.."" The following files may have dependencies that can not be determinited automatically. Please confirm that all dependencies have been added to the project c:\windows\system32 \macromed\flash\flash.ocx..""  Please help me to solve this..
       (HRS + Design + PROCESS + NC_PRG + CHK_HRS) TOT_US
SELECT get_secc_hourlyrate(10022) GHRLY_RATE from dual,

We have a job that runs every 15 minutes it sends emails to specific recipients from the db using xp_sendmail sql 2000.  Last night it starting sending the same email every 1 minute, and we cannot stop it.  We have restarted the server and it still continues.  We have no idea what to do at this point, any ideas would be great help.
I do not know how to use SQL or VBA.  (I used to write scripts in Borland dBase a long time ago, but I've atrophied since then.)   I can build somewhat complex databases, queries, and reports using tables in Access.  I frequently use Excel data tables as Access data sources.  And I can build basic Excel spreadsheets using many of the built-in functions.  I currently have a large database I need to analyze.  Each line in my Access table has one set of parameters (3 to 5 numbers) that needs analysis (return one number).  The analysis for that one set of parameters is too difficult to perform in Access using a long series of queries, and I doubt I could construct it.  Although it will take some time to build the spreadsheet in Excel, it should be straight forward to do the calculations and make the final decision in Excel on a single set of parameters.  However, there is no way I could construct that on a single Excel line, and then repeat that line down hundreds of thousands of lines in Excel.

How can I pass one set of parameters, say 5 numbers, to 5 specific cells in an Excel spreadsheet, and read  the result cell back into Access?  Running the Access query will need to complete the same analysis on every line in the Access data table, and fill in the results column in the same Access parameters table or a different Access table linked to the original parameters table.  Just to be clear, I'm not asking how to use a single Excel internal function, such as Present Value, in …
I am working with a third-party MySQL database.  I am trying to decode a field.  This field contains the IP address of a computer.  I have been told this field is in base64 format.  I am not able to figure this out.  Below I have an example of some methods that I have tried using, with no luck.  

from datbasename.device;

Open in new window

I am running MySQL 5.6.32.

Does anyone have any suggestions on how I can decode these values?

Many Thanks!
I have a pl/sql  procedure this is the code:
d VARCHAR2(5000);
    SELECT DBMS_LOB.substr( doc, 4000, OFFSET) INTO d
    FROM docClob
    WHERE ROWNUM <  2;
    opcDoc := d;
END ;  
I've tested it pl/sql developer with offset = 1 and doesn't return any thing and doesn't raise any errors.
I tested it in sql using this code:
SELECT DBMS_LOB.substr( doc, 4000,1)
FROM docClob
and it returns the first 4000 characters of the clob.
I see bit of code:


What is the difference between that VS simply doing this:


Following on from this post Wordpress SQL query help

Each post 'should' have multiple entries (30--50 on average) in wp_postmeta as a result of running the previous  I've now discovered some where the metadata is missing

using the sample data in  the last post how find all the post which have less than 5 ?

In sudo code

select p.`ID`,p.post_title
from wp_posts p, wp_postmeta m 
where p.post_status ='publish' and 
p.`ID`= m,post_id in (select post_id from wp_postmeta where count(m.meta_key) <=5) 

Open in new window

New benefit for Premium Members - Upgrade now!
New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Hi Experts,

I have a case when statement
when cce.CVA_StatusID is not null then cvs.StatusType else 'No Status' end as [Status]

Open in new window

and would like to do:
INNER JOIN  @SEV as sta on sta.stat = Status

But one can see this is not the correct way to do this.

Any idea would be great?  Maybe a CTE?  but would need help.

Thank You....
So, a client would like to be able to have their employees receive a message if they haven't entered in time within the last 7 days. Specifically Monday - Monday at 12:00PM. If the employees have not entered in time by noon, they should be locked down and only allowed to enter time for dates that fall within the last 7 days. The code is written in VB.NET and utilizes SQL and Stored Procedures heavily. I was hoping to get some ideas in regards to possible ways to go about this.
how to update column of 1 table from column of another table  without having any reference
Hi Guys,

I need help with a SQL query / script,

We have two tables,
SQL TABLE 01 - with primary employee records , identified by the person's ID number.
SQL TABLE 02 - with multiple records for each employee, relating back to the primary table by employee ID number.

Ideally I would like to extract the information to Text / CSV for only a specific list of employee ID numbers.

For example:  
A text file (A) with 1000 employee ID numbers.
A script to read the text file (A), do a lookup on each employee in SQL TABLE 01.  Write the result to another text file (B).
The same script to lookup the same employee records by ID number in SQL TABLE 02, write all relating records to Text File (B).

Thus, the text file (B) will have primary and secondary employee records from the list of employee ID numbers in text file (A).
Dear All

We have some servers physical and Virtual with WIn 2012 R2 installed.
SQL server has been installed.

Now issue is all server memory is going above 90% and servers are very slow.
My Tables has the following fields:
ERRC, Stock Nbr, Count of Stock, Qty Requested and Qty of Stock.

My query needs to group by ERRC, count records for each ERRC, Count Unique Stock for Errc, multiple unique stock * Qty request

Query Syntax





SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.