sql-server-2005

Need to convert the DataTable return type to string

大憨熊 提交于 2020-01-06 07:25:14
问题 I have a function to return the list of tables having primary key in a datatable, but now the need is to get the table list in the string return type. My method is as follows: public DataTable GetAllPrimaryKeyTables (string localServer, string userName, string password, string selectedDatabase) { // Create the datatable DataTable dtListOfPrimaryKeyTables = new DataTable("tableNames"); SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder(); objConnectionString

How to convert string to integer - weird format

孤者浪人 提交于 2020-01-06 07:25:09
问题 I have a field named: pa_value wich keeps varchar records Now this field contains records like: - 0.5582% - 0.6985% - -0.1589% - 0.9856% - -0.6589% I'm getting these results using the following code: CAST (replace (p7.pa_value ,'%','') AS float (3,0)) as TotalMargin What I'm trying to do is to remove everything and leave just 2 characters(or 3 if there is a -(minus) infront of the string). It should be looking like this: - 55 - 69 - -15 - 98 - -65 I tried to cast it as a float and then to

SQL going nuts! does not accept parameters,?

徘徊边缘 提交于 2020-01-06 07:09:41
问题 alt text http://img24.imageshack.us/img24/3365/sqlnuts.jpg well heres the code public void select_table_names() {//start /* display all tables*/ string commandString = null; SqlConnection conn = null; SqlCommand command = null; SqlDataReader reader = null; ArrayList list = new ArrayList(); try { // commandString = "SELECT TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES ";// @table "; //string columns; //string tables; //columns = "TABLE_SCHEMA"; //tables = "INFORMATION_SCHEMA.TABLES";

sql 2005 join results

ぃ、小莉子 提交于 2020-01-06 06:16:05
问题 HI, Using Microsoft SQL Server 2005: I have a table "test": id, link_id, name 1 11 test1 2 11 test2 3 11 test3 4 12 test4 Is there a way to query this, and return the results grouped by "link_id", with the names joined? EG, SELECT link_id, name FROM test WHERE ??????? results: link_id, name(s) 11 test1, test2, test3 12 test4 回答1: The blackbox way of doing this is with a CROSS APPLY and FOR XML PATH: declare @t table (id int, link_id int, name varchar(max)) insert into @t select 1, 11, 'test1'

t-sql string concatenation

痞子三分冷 提交于 2020-01-06 06:11:24
问题 i have a table that has following column Type -------- type 1 type 2 type 3 How can i convert the above to a string like ('type 1', 'type 2', 'type 3') I want to use the output in my t-sql query with IN clause. Something like select * from TableA where SomeColumn IN ('Type 1','Type 2', Type 3') I used to following to come up with output (type 1, type 2, type 3) select '(' + STUFF((select ', ' + Type from TableA for xml path ('')),1,2,'') + ')' But dont know how to insert the single quotes.

t-sql string concatenation

寵の児 提交于 2020-01-06 06:11:13
问题 i have a table that has following column Type -------- type 1 type 2 type 3 How can i convert the above to a string like ('type 1', 'type 2', 'type 3') I want to use the output in my t-sql query with IN clause. Something like select * from TableA where SomeColumn IN ('Type 1','Type 2', Type 3') I used to following to come up with output (type 1, type 2, type 3) select '(' + STUFF((select ', ' + Type from TableA for xml path ('')),1,2,'') + ')' But dont know how to insert the single quotes.

SQL: Having trouble with query that gets percentages using aggregate functions

你说的曾经没有我的故事 提交于 2020-01-06 05:25:11
问题 I'm not an expert in SQL by any means, and am having a hard time getting the data I need from a query. I'm working with a single table, Journal_Entry, that has a number of columns. One column is Status_ID, which is a foreign key to a Status table with three values "Green", "Yellow", and "Red". Also, a journal entry is logged against a particular User (User_ID). I'm trying to get the number of journal entries logged for each Status, as a percentage of the total number of journal entries logged

how to display only aggregate or flagged results in a Case statement

一世执手 提交于 2020-01-06 04:10:11
问题 I have a query that gets break time exceptions. I use Case statements to flag the records. The problem is, I only want to list those that are flagged or have a "1" in the Skipped break, or "ShortBreak" column? SELECT lEmployeeID, sFirstName, sLastName, SUM(TotalHours) AS TotalHours, DATEDIFF(mi, MIN(dtTimeOut), MAX(dtTimeIn)) AS BreakTime, CASE WHEN SUM(ftc.TotalHours) > 6 AND DATEDIFF(mi, MIN(ftc.dtTimeOut), MAX(ftc.dtTimeIn)) < 0 THEN 1 ELSE 0 END AS SkippedBreak, CASE WHEN DATEDIFF(mi, MIN

Create more than one non clustered index on same column in SQL Server

烈酒焚心 提交于 2020-01-06 04:01:07
问题 What is the index creating strategy? Is it possible to create more than one non-clustered index on the same column in SQL Server? How about creating clustered and non-clustered on same column? Very sorry, but indexing is very confusing to me. Is there any way to find out the estimated query execution time in SQL Server? 回答1: The words are rather logical and you'll learn them quite quickly. :) In layman's terms, SEEK implies seeking out precise locations for records, which is what the SQL

Storing Connection Strings in Registry?

不想你离开。 提交于 2020-01-06 03:34:12
问题 We decided to use the registry for handling our deployment with connection strings in our VB.net application. The requirements are: If the program cannot connect to the server, first check the registry for a connection string. IF not, create the folder and fill in the name, type, and data. Make sure its encrypted. I have never edited or created anything in the registry. Where do I start? If anybody has any code samples or links to articles I would really appreciate it. 回答1: It looks like this