Go Premium for a chance to win a PS4. Enter to Win



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 have a form that has 6 data blocks and several items. When a user enters/queries an item, just before the user changes any item I would like to save the old values to a database table by using a trigger. Then I will later figure out how to save the changes to another table by using a trigger.
Visualize your virtual and backup environments
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Hi Team,

My Db is in simple recovery mode.  This is not PROD. So backups are not important for us.

What if i shrink .ldf files? will it cause fragmentation?
Want to build powerful, database-driven websites? You can learn how in the November Course of the Month, with a focus on PHP, MySQL, and CakePHP MVC framework.
I have been working on a SQL routine that pulls POs from a legacy application and inserts them into a modern ERP solution. In our data center the process pulls in all 20,000 POs in less than 20 minutes. We just tried to deploy this routine in the customer's environment and the process took over 10 hours. This routine deals with about 10 tables in two databases that are housed in the same instance of MS-SQL 2012. What tools can I run on both ends to identify what is causing the bottleneck on their system?

I am trying to import these Apache logs into an SQL Database but am unable to do so.

When I run the code below I get the following Error:

Msg 4860, Level 16, State 1, Line 4
Cannot bulk load. The file "C:\LOGS\access.2017.11.16.log" does not exist or you don't have file access rights.

Can I I Import all Files without checking for a date? 

(1 row affected)

Open in new window

/*****This is the share location of the log file in a variable*****/
DECLARE @FileLocation varchar(max)
SET @FileLocation = 'C:\LOGS\'

/*****This is the name of the start the file name in a variable********/
DECLARE @FileName varchar(max)
SET @FileName = 'access.'

/********This is the extention of the log file in a variable*******/
DECLARE @FileEXT varchar(4)
SET @FileEXT = '.log'

/*************This gets todays date in a variable*************/
Declare @date varchar(max)
set @date = (SELECT convert(varchar, getdate()-4, 102))

/********This puts all of the file share and info in one variable name************/
DECLARE @FilePath varchar(max)
Set @FilePath = @FileLocation + @FileName + @Date + @FileEXT

/*********** This is the SQL to insert and its written into a variable and executed************/
DECLARE @SQL nvarchar(max)

SET @SQL = N' use Downloads 
		   INSERT BulkInsert 
		   FROM "' + @FilePath + 
		   '" WITH 
		   FIELDTERMINATOR = '','', 
		   ROWTERMINATOR = ''\n'')'
EXEC  sp_executesql @SQL


Open in new window

I have a database server that is about 4 years old.  we have a bunch of users that point their applications to this server.

the name of the server is    Alpha

We want to upgrade the sql server version from 2012 to 2016.   I think i would like to create a new server and do a clean install of sql server instead of doing an in-place upgrade.

So the new server would be bravo......  (if we do not do an in-place upgrade)
isn't it true that if i get the permissions right on bravo and restore all the databases on bravo.  that i could thereotically change the name of Alpha to lets say Alpha1 and then rename Bravo to Alpha that the users would not need any configuration changes.

Can someone please verify or send me to a document that outlines the best way to do this.
SQL Server 2012

1) Why does SSMS duplicate Role permission when I add it through a SQL statement?
2) Is it a problem?

If I add permission to a Role in SQL Server through ssms I can find the object and and check the permission (eg grant Insert and Update)
However I have noticed if I add the permission through a SQL statement,  I end up with 2 Insert check boxes and 2 Update check boxes.
         GRANT Insert ON  [dbo].[tbl_Menu_Items] TO [RL_Admin]
         GRANT Update ON  [dbo].[tbl_Menu_Items] TO [RL_Admin]

SQL Roles Issue
Thanks in advance for any help
how do I return records from a table where the field create date (date time)  is equal to todays date?  I can't hardcode todays date so I will need to use getdate() or something.

and a relation table shown in picture


can i get mutual friend ?

i have
Following Query =
 "SELECT `user_id` FROM " . T_USERS . " WHERE `user_id` IN (SELECT `following_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `active` = '1' ";

Open in new window

Follower Query =
" SELECT `user_id` FROM " . T_USERS . " WHERE `user_id` IN (SELECT `follower_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `active` = '1') AND `active` = '1'";

Open in new window

perfectly working
Dear Experts,

Below is my SQL view code to return the information I need to create a page

SELECT        TOP (100) PERCENT dbo.tblEntry.EntryID, dbo.tblClient.ClientForeName, dbo.tblClient.ClientSurName, dbo.tblClient.ClientID, dbo.tblHorse.HorseID, dbo.tblHorse.HorseName, dbo.tblEntry.EntryBridleNumber, 
                         dbo.tblEntry.EntryStartTime, dbo.tblClass.ClassID, dbo.tblShow.ShowID, dbo.tblEntry.EntryApproved, dbo.tblEntry.EntrySectionPlace, dbo.tblEntry.EntryPercentageMark, dbo.tblEntry.EntryResultsMark, 
                         dbo.tblEntry.EntryResultsPlace, dbo.tblEntry.Section, dbo.tblEntry.EntryCancelled, dbo.tblEntry.EntryCollectiveMark, dbo.tblEntry.EntryResultsMoney, dbo.tblEntry.EntryNotes, dbo.tblClass.ClassNumber, 
                         dbo.tblTest.TestName, dbo.tblShow.ShowStartDate, dbo.tblClient.ClientBDNumber, dbo.tblClient.ClientBSJANumber, dbo.tblHorse.HorseBSJANumber, dbo.tblHorse.HorseBDNumber
FROM            dbo.tblEntry INNER JOIN
                         dbo.tblClient ON dbo.tblEntry.RiderID = dbo.tblClient.ClientID INNER JOIN
                         dbo.tblHorse ON dbo.tblEntry.HorseID = dbo.tblHorse.HorseID INNER JOIN
                         dbo.tblClass ON dbo.tblEntry.ClassID = dbo.tblClass.ClassID INNER JOIN
                         dbo.tblShow ON dbo.tblClass.ShowID = dbo.tblShow.ShowID INNER JOIN
                         dbo.tblTest ON dbo.tblClass.TestID = dbo.tblTest.TestID

Open in new window

Veeam Disaster Recovery in Microsoft Azure
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


I have data in three columns in the database that represents three levels.
Column 'Amt' is the top level
Column 'Herred' is the middle level
Column 'Sogn' it the bottom level

I have made this page: http://kroweb.dk/gfdev/dropdown/ where I have the three levels represented in three select boxes.

What I need is this:
The 'Amt' box should reflect a dropdown box with the content of the column 'Amt' in the database
The 'Herred' box should reflect a dropdown box with the content of the column 'Herred' within the chosen 'Amt'
The 'Sogn' box should reflect a dropdown box with the content of the column 'Sogn' within the chosen 'Amt' and 'Herred'.

I have this HTML (commented where I believe something more is needed :) :
                    <!-- Søge felter -->
        <div class="container" style="width:100%;padding-top:10px;background-color:#f6f6f6;">

            <!-- HEADER START -->
            <div class="row" id="header">
                <form method="POST" style="margin-left:30px;"> 

                        <select id="amt" name="amt">
                        <option value=""></option>
                        <option value="Content of column 'Amt'">Content of column 'Amt'</option> <!-- something else needed -->

                        <select id="herred" name="herred">

Open in new window

Hello, I have this query that has data for every minute which I have attached some data of the table.

I want to group this into 4 hours starting from 00:00, but I don't want to sum or average the value in the column [Last] I just want to return that value in the [Last] column as it is at that specific grouped hour.

SELECT b.[timestamp], b.[id], b.[Date], b.[HourMin], b.[Min], b.[Last]
FROM [vw_BassLineDataTimestamp] b

Open in new window

So should return this instead

timestamp                             id                                                      Date             HourMin     Min      Last
2017-11-20T08:00:48.467      BTC-LTC_2017-11-20_08:00      2017-11-20      08:00          0              0.00890995
2017-11-20T04:00:50.583      BTC-LTC_2017-11-20_04:00      2017-11-20      04:00          0              0.009015
2017-11-20T00:00:51.573      BTC-LTC_2017-11-20_00:00      2017-11-20      00:00          0              0.0089

Thanks in advance.

Also if possible could I amend the hour interval so instead of 4 hours (240 min) to any say like 5.71667 hours (343min) or any interval would be great.

Kind regards
Dear Experts,

MS SQL 2014 Enterprise

I am assisting my client to run the SQL replication.

However, there was a database that is configured to use DB restore with norecovery and restore with a differential backp.

I later accidentally ran the snapshot agent and now it keeps displaying "the replication agent has not logged a progress message in 10 minutes".

How can I set it back to "Never started"?
I have an SSRS combo box that will pass 1 of 3 values to my stored proc.


I need the report to do the following based on one of these 3 options being picked.

If the parameter Native is picked...then it should be be equal to the columns value in the report of Native.
the same if Linked is chosen..

If All is chosen it should return anything in this column...which could be "Native" , "Linked", '' , NULL

Please help me build the where clause to handle this.

Here is what I have ..but its not working.

(((@NativeLinked = 'Native' or @NativeLinked= 'Linked') and t2.[Native/Linked] = @NativeLinked) or ((@NativeLinked = 'All') and t2.[Native/Linked] is null or  @NativeLinked = 'Native' or @NativeLinked= 'Linked'))

I want to send email groupwise. For example, i want to send emails to department heads for the people working in their departments. I have 10 departments so need to send 10 emails to their heads regarding the attendance of their respective department staff.

Any solution, plz advice
I have a parent form of movie volumes ("frmVolumes", home-recorded VCR movies), and one volume can have multiple programs (shown in "fsubPrograms", individual movies or TV shows).  Those link with no problem.  When the frmVolumes displays, the appropriate programs display in fsubPrograms, based on frmVolume's recordsource's primary key, which is a hidden field on frmVolumes.

However, I can't get another level of subform (fsubActors) to display appropriate actors based on the highlighted program's recordsource's primary key, which is a hidden field on fsubPrograms.  It looks like all actors are loading.

I think my problem lies in the order in which Access loads forms.  Rather than use form properties for link master and child fields, I am using SQL strings in the Form_Current event.  This is a new technique for me, but I have it working and understand it for one main form and one subform.  In my experience, the subform's recordsource is retrieved before the main form's recordsource.

Linking the subform to another yet a further subform seems to be the problem.  Another version of this database that does use form properties for linking does work properly, and I get the correct actors.  I have also tested the query to verify that it only brings back the actors I want.

Here are my queries, just for a validation.  Can someone explain what I need to do so that the three recordsources are loaded in the correct order?  Am I missing a Requery/Refresh/Repaint?

Hi Expert,

Please help me export data from my sql to text file with comma delimited format. I have SP that generates the data and i want it from the user interface to download the data and save is as text comma delimited.

Many Thanks.
Hello Experts,
I would like to know if there are any PC utilities to read CSV files other than Excel. I see a host of them online, but I would really like your recommendation based on your personal experiences.
The following chart has a filter applied, keyword "bingo"


Unfortunately the HTML publishing feature does not seem to work (the filter gets removed)

Is there any workaround i can use to publish the filtered version of the chart (apart from creating a new table with the filtered data)?

I want to be able to show the chart on it's own.

This question is as aside from https://www.experts-exchange.com/questions/29069155/Creating-a-dynamic-query-for-Google-Fusion-Tables.html

What is SQL Server and how does it work?
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


I have this SQL query:
           $query = $mysqli->prepare("SELECT * FROM ft WHERE Aar = ? AND AmtHerredSognGade LIKE '%".$sogn."%'");
            $query->bind_param("s", $start);

Open in new window

I need to be able to put in a constant in the search string before the result of $sogn.
E.g if the $sogn returns "Gudhjem" I need to put in a string before Gudhjem, in this case Bornholm, so that the total searchstring becomes "Bornholm Gudhjem".
The string I need to put in before the $sogn are represented in the table in a column with the headline "Amt" and I would naturally like to pull it from there.
I know that the string for searching for $sogn are broad with jokers but it have to be that because the "AmtHerredSognGade" field in the table is a combined field from where I need to pull out the part matching the query.

I hope that somebody have the golden idea to fix this :)
I have formula filed f1 do (field1-feld2) during tow dates
then how to use something like this in my c# code
DB db = new DB();
            DateTime StartDate;
            DateTime EndDate;
            StartDate = Convert.ToDateTime(dtpfrom.Value.ToString("yyyy-MM-dd"));
            EndDate = Convert.ToDateTime(dtpto.Value.ToString("yyyy-MM-dd"));
            FrmViewer fv = new FrmViewer();
            crtunderMedicineRoof rpt = new crtunderMedicineRoof();
            string sql = "";
            sql = "  {View1.MedicineDate}in #" + StartDate + "# to #" + EndDate + "#";
            param = "سقف العلاج للفترة من  " + " " + dtpfrom.Value.ToString("yyyy-MM-dd") + " الي" + " " + dtpto.Value.ToString("yyyy-MM-dd");
            if (ckb_overRoof.Checked == true)
                sql += "and  View1.f1<0)";//using formula field here
            rpt.SetParameterValue(0, param);
            //rpt.SetParameterValue(1, p);
            rpt.RecordSelectionFormula = sql;
            rpt.SetDatabaseLogon("cost", "cost");
            fv.crystalReportViewer1.ReportSource = rpt;
I created an provider driver for SQl server using the user login for authentication , and tested successfully . But when my vb code tries to access the filedsn I created it gives me an error , saying Runtime error '-2147217843 (80040e4d)',
the code is :
Sub main()
    Dim Db As ADODB.Connection
    Dim RS As ADODB.Recordset
    Dim CMD As ADODB.Command
       Set Db = New ADODB.Connection
       Set RS = New ADODB.Recordset
       Set CMD = New ADODB.Command
    Db.CursorLocation = adUseClient
    Db.Open "Provider=SQLNCLI11;server=server-pc;Database=IFS_803_13960820;UserId=farauser;Password=tycedar"

  CMD.ActiveConnection = Db
  CMD.CommandType = adCmdStoredProc
  CMD.CommandText = "__GASKARTPEYMAN__"
  CMD.Parameters.Append CMD.CreateParameter("@PNO", adInteger, adParamInput, 10, 31529)
 Set RS = CMD.Execute
End Sub
As DBA's point of view
I am working as a MS SQL DBA, I want to know,
What is the Difference between MS SQL Server and PostgreSQL?
I have a stored proc that is using ROW_NUMBER to generate a specific sequence. Based on the last # generated, I need to use this # as a seed value in another stored proc to continue the sequence.

Is it possible to insert the last row number generated into a table? Is there a more elegant solution to this?

Thanks in advance!

Please go through the image.

I found this on one of our customer sql server 2008 R2 cluster. This is Active/Passive. In this image i can see 2 nodes are mentioned as Preferred owners? What does it means? is there any impact?  


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.