sql-server-2008-r2

SQL Server 2008 R2 can't connect to local database in Management Studio

血红的双手。 提交于 2019-12-18 10:59:28
问题 I am using SQL Server 2008 R2 Express. I first installed SQL Server 2008 R2 Express Management Studio and then I installed SQL Server 2008 R2 Express. I have the instance SQLEXPRESS running and it is set to automatic. I am trying to connect to it locally using Windows authentication - server name is set to local and the username is grayed out and set to my profile username. When I try to connect I get the following error: Have I installed the wrong SQL Server Management Studio? 回答1: If your

Find the last time table was updated

廉价感情. 提交于 2019-12-18 10:56:39
问题 I want to retrieve the last time table was updated(insert,delete,update). I tried this query. SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('T') but the data there is not persisted across service restarts. I want to preserve the stats even if the service restarts. How can I achieve it? 回答1: If you're talking about last time the table was updated in terms of its structured has changed (new column added, column changed etc.) - use this query: SELECT name,

SSIS transformation (almost like a pivot)

喜你入骨 提交于 2019-12-18 09:27:45
问题 I have the following data coming in to SSIS Set Value --- ------- 1 One 1 Two 1 Three 2 Four 2 Five 2 Six I want to transform it to read Set ValueList --- ------- 1 One, Two, Three 2 Four, Five, Six How do I do this in SSIS? 回答1: There is a pivot task in the data flow transformations. You could try it, but I'll warn you that we have been less than hapy with it's implementation. Alternatively, you could use the dataflow to put the data into a staging table, and pivot using SQL or do the pivot

SQL Server 2008 R2 using PIVOT with varchar columns not working

人走茶凉 提交于 2019-12-18 09:18:12
问题 I'm using SQL Server 2008 R2, I have this simple table What I was trying to do is make a selection from this table and get this following result x | 1 | 2 | 3 --+------------+-------------+------------ 1 | first 1 | first 2 | first 3 2 | Second 1 | second 2 | second 3 I thought that can be done with PIVOT I don't know much about PIVOT AND all my search result found using PIVOT with Count() . SUM() , AVG() which will not work in my table since I'm trying to PIVOT on a varchar column Question

Fill In The Date Gaps With Date Table

▼魔方 西西 提交于 2019-12-18 09:02:48
问题 I have two tables. An orders table with customer, and date. A date dimension table from a data warehouse. The orders table does not contain activity for every date in a given month, but I need to return a result set that fills in the gaps with date and customer. For Example, I need this: Customer Date =============================== Cust1 1/15/2012 Cust1 1/18/2012 Cust2 1/5/2012 Cust2 1/8/2012 To look like this: Customer Date ============================ Cust1 1/15/2012 Cust1 1/16/2012 Cust1

TSQLQuery only streams first 1MB of data correctly for large strings

半城伤御伤魂 提交于 2019-12-18 08:57:14
问题 (see Edit #1 with stack trace and Edit #2 with workaround at end of post) While troubleshooting TSQLQuery.FieldByName().AsString -> TStringStream Corrupts Data, I found that a TSQLQuery.FieldByName().AsBytes will only stream exactly 1MB of varchar(max) data correctly. Using WireShark, I verified that the data is all being handed to the Delphi app correctly . I verified that it always writes out the correct number of bytes to the output file, but any bytes that exceed exactly 1MB are null

Create SQL Server table programmatically

空扰寡人 提交于 2019-12-18 08:53:11
问题 I need to programmatically create a SQL Server 2008 table in C# such that the columns of the table should be generated from a list of columns (each column name is the name of a row in the table) My question is what is the command string to loop through the list of columns and creates the table's recorded: List<string> columnsName = ["col1","col2","col3"] I want to create a table with the columns in the columnsName . But since the list size in not constant, I need to loop through the list to

How to convert a SQL Server cursor to MySQL equivalent

杀马特。学长 韩版系。学妹 提交于 2019-12-18 05:11:59
问题 How can I convert the procedure below to MySQL format? Here is the piece to be converted: DECLARE @CurrentFirstName varchar(300) DECLARE @CurrentAge INT DECLARE CursorName CURSOR FAST_FORWARD FOR SELECT Firstname,Age FROM Customers OPEN CursorName FETCH NEXT FROM CursorName INTO @CurrentFirstName, @CurrentAge WHILE @@FETCH_STATUS = 0 BEGIN IF @AGE>60 /*this is stupid but we can apply any complex condition here*/ BEGIN insert into ElderCustomers values (@CurrentFirstName,@CurrentAge) END FETCH

define a computed column reference another table

久未见 提交于 2019-12-18 03:41:48
问题 I have two database tables, Team ( ID, NAME, CITY, BOSS, TOTALPLAYER ) and Player ( ID, NAME, TEAMID, AGE ), the relationship between the two tables is one to many, one team can have many players. I want to know is there a way to define a TOTALPLAYER column in the Team table as computed? For example, if there are 10 players' TEAMID is 1, then the row in Team table which ID is 1 has the TOTALPLAYER column with a value of 10. If I add a player, the TOTALPLAYER column's value goes up to 11, I

define a computed column reference another table

给你一囗甜甜゛ 提交于 2019-12-18 03:41:03
问题 I have two database tables, Team ( ID, NAME, CITY, BOSS, TOTALPLAYER ) and Player ( ID, NAME, TEAMID, AGE ), the relationship between the two tables is one to many, one team can have many players. I want to know is there a way to define a TOTALPLAYER column in the Team table as computed? For example, if there are 10 players' TEAMID is 1, then the row in Team table which ID is 1 has the TOTALPLAYER column with a value of 10. If I add a player, the TOTALPLAYER column's value goes up to 11, I