Unable to Subtract Dates SQL Server

Using the sample data you posted (and adapting it slightly), here is my attempt to solve the problem: SELECT BASESCORE, Datediff(dd, MINDATE, MAXDATE) FROM (SELECT BASESCORE, Cast(Max(DATETIME) AS DATETIME) MaxDate, Cast(Min(DATETIME) AS DATETIME) MinDate FROM table1 GROUP BY BASESCORE)T You can take a look at the full working version on SQL Fiddle. Let me know … Read more

'Must declare the scalar variable "@thisuser".' [closed]

You forgot to add the parameter to your SqlCommand. You command does not know which value to fill in for “@thisuser”. You can add parameters like this: sqlCommand.Parameters.Add(“parameter_name”, SqlDbType.TargetSqlType).Value = parameter_value; So you code would look like this: private void btnPersonalInfo_Click(object sender, EventArgs e) { var username = “foo bar”; sqlcon.Open(); string query = “SELECT … Read more

How can I round a value in SQL

ROUND documentation on MSDN select [raw] = 555.81, [rounded] = round(555.81, 0), [truncated] = round(555.81, 0, 1) Result: | raw | rounded | truncated | |——–|———|———–| | 555.81 | 556 | 555 | SQL Fiddle: http://sqlfiddle.com/#!6/9eecb7db59d16c80417c72d1/5290