sql-server-2008

SQL aggregation query, grouping by entries in junction table

耗尽温柔 提交于 2019-12-13 01:07:49
问题 I have TableA in a many-to-many relationship with TableC via TableB. That is, TableA TableB TableC id | val fkeyA | fkeyC id | data I wish the do select sum(val) on TableA, grouping by the relationship(s) to TableC. Every entry in TableA has at least one relationship with TableC. For example, TableA 1 | 25 2 | 30 3 | 50 TableB 1 | 1 1 | 2 2 | 1 2 | 2 2 | 3 3 | 1 3 | 2 should output 75 30 since rows 1 and 3 in Table have the same relationships to TableC, but row 2 in TableA has a different

ODBC and SQL Server 2008: Can't use prepared statements?

懵懂的女人 提交于 2019-12-13 01:06:28
问题 OK, so I cannot get this to work (either): $stmt = odbc_prepare($conn, "SELECT * FROM Users WHERE username=?"); odbc_execute($stmt, array($username)); $user = odbc_fetch_object($stmt); $stmt = $pdo->prepare("SELECT * FROM Users WHERE username=?"); $stmt->execut(array($username)); $user = $stmt->fetchObject(); Both return the same errors: Warning: odbc_execute(): SQL error: Failed to fetch error message, SQL state HY000 in SQLExecute in user.php on line 24 Anyone know if it's possible to solve

Using R with RODBCext and RODBC to execute a SQL stored procedure

﹥>﹥吖頭↗ 提交于 2019-12-13 00:49:26
问题 I am using the RODBCext package and the RODBC package to execute a stored procedure in SQL server 2008 using R. If I use this code the stored procedure works. query <- "EXEC [dbo].[usp_SchoolMerge] @Number = ?, @Name = ?, @Type = ?, @Comments = ?, @DualEnrollment =?, @CEP = ?, @DistrictGuidId = ?, @ImportName = ?, @ImportID = ?" query <- gsub("[[:space:]]+", " ", query) con2 <- odbcConnect("database", uid="userid", pwd="password") for(i in 1:nrow(us11_12_00_school)) { sqlExecute(con2, query,

SQL for obtaining data any previous month

落爺英雄遲暮 提交于 2019-12-13 00:46:52
问题 Hi im still fairly new to SQL script and i have written some below to fetch what i hope will be ALL of the previous months data when run at any given date, regardless of the number of days in a month The table date format is 2013-05-10 00:00:00.000 im just after an expert eye to look at the script and advise if i have got it right or wrong and where if i have please: SELECT [Circuit Number] ,[Request Number] ,[RequestDate] FROM [QuoteBase].[dbo].[Requests] WHERE RequestType LIKE 'Cancel%' AND

SQL query to find the sum of all rows and sum of portions of rows within a group by clause

早过忘川 提交于 2019-12-13 00:46:46
问题 I am trying to build a query for a SQL Server 2008 database. The query would group the SID and Date column and sum the Profit column. The query also needs to find the sum of Profit for all rows having the same units toward the end of a day. in this case, the units value of 1 switched from -1 at 12:54PM to 1 and remained the same until the last record for that day which is at 1:15PM. SID Date Profit Units RowID ------------------------------------------------------- 1 7/26/10 1:15 PM -25 1 1 1

How to decode base64 unicode string using T-SQL

痞子三分冷 提交于 2019-12-13 00:44:41
问题 Can't decode turkish characters in base64 string. Base64 string = "xJ/DvGnFn8Onw7bDlsOHxLDEnsOcw5w=" When I decode it must be like this : 'ğüişçöÖÇİĞÜÜ' I try to decode like this : SELECT CAST( CAST(N'' AS XML).value('xs:base64Binary("xJ/DvGnFn8Onw7bDlsOHxLDEnsOcw5w=")' , 'VARBINARY(MAX)') AS NVARCHAR(MAX) ) UnicodeEncoding ; Based on this answer : Base64 encoding in SQL Server 2005 T-SQL But have response like this : '鿄볃앩쎟쎧쎶쎖쒇쒰쎞쎜' Base64 string is correct because when I try decode in

How to set If condition in Where clause in Sql

痞子三分冷 提交于 2019-12-13 00:36:51
问题 I want to display a criteria having multiple conditions, but if any condition is null or not having any value than how to set in where clause. Example: where SR.fk_Designation_ID = @pk_Designation_ID and SR.fk_SeniorityCategory_ID = @pk_SeniorityCategory_ID and SR.IsCurrent_Appointment = 1 and SR.fk_SeparationType_ID is null order by Senority_Joining_For_Order,E.Date_Of_Birth here if @pk_SeniorityCategory_ID is null than I don't want to include the and SR.fk_SeniorityCategory_ID = @pk

how to sum the time grouped by individual day in Sql-server

烂漫一生 提交于 2019-12-13 00:29:36
问题 I have a table with id, play, starttime and endtime. I want to find the total play time per day. I think the query will be similar as the following but I am sure it is not right. It will be also very convenient if i get 0 when no game is played but if it is difficult I dont mind. Select id, play, date, CASE WHEN datediff(day, starttime, endtime) = 0 then sum(totaltime) END as TimePerDay from cte where starttime >= '2015-05-30 17:11:34.000' group by id, playtime, starttime, endtime I am

Classic ASP global.asa SQL Server 2008 connection string

◇◆丶佛笑我妖孽 提交于 2019-12-13 00:28:10
问题 I have been given a web application written in Classic ASP to port from Windows 2003 Server (SQL Server 2000 and IIS 6) to Windows 2008 Server (SQL Server 2008 and IIS 7.5). The site uses a GLOBAL.ASA file to define global variables, one of which is the connection string ( cnn ) to connect to SQL Server. Below is the (old) connection string from GLOBAL.ASA : Sub Application_OnStart Dim cnnDem, cnnString Set cnnDem = Server.CreateObject("ADODB.Connection") cnnDem.CommandTimeout = 60 cnnDem

Using SQL Server Express 2008 with SQL Server 2005 database -how to check for compatibility

不想你离开。 提交于 2019-12-13 00:24:10
问题 I am using SQL Server 2008 express edition but I want to make my databases still in 2005. How can I set it up to only show features that a 2005 database can use? Like for instance I don't remember there being a "date" type. I only remember "dateTime". I don't want to be using features that 2005 can't support and I later on upload my db to the my hosting site that uses 2005 still and find out I am using things not supported by it. 回答1: You won't be able to upload the database, just a script of

工具导航Map