sql-server-2005

Add Column on SQL Server on Specific Place?

落爺英雄遲暮 提交于 2019-12-19 19:31:34
问题 I would like to know if there's a way to add a column to an SQL Server table after it's created and in a specific position?? Thanks. 回答1: You can do that in Management-Studio. You can examine the way this is accomplished by generating the SQL-script BEFORE saving the change. Basically it's achieved by: removing all foreign keys creating a new table with the added column copying all data from the old into the new table dropping the old table renaming the new table to the old name recreating

Multi-base conversion - using all combinations for URL shortener

不打扰是莪最后的温柔 提交于 2019-12-19 11:36:12
问题 I am making an URL shortener, and I am struggling with the optimal way of encoding a number (id) into a character string. I am using the characters 0-9,A-Z,a-z so it will basically be a base-62 encoding. That is pretty basic, but it doesn't make use of all possible codes. The codes that it would produce would be: 0, 1, ... y, z, 10, 11, ... zy, zz, 100, 101, ... Notice that the codes 00 to 0z is not used, the same for 000 to 0zz, and so on. I would like to use all the codes, like this: 0, 1,

Split sql string into words

China☆狼群 提交于 2019-12-19 10:46:06
问题 I want to split string into words like below, the output of all the string should be same: INPUT: 1. This is a string 2. This is a string 3. This is a string 4. This is a string OUTPUT: This is a Means, that I want first three words from the sentence, irrespective of the spaces. 回答1: Try this: declare @s1 varchar(3000) ; declare @xml xml,@str varchar(100),@delimiter varchar(10), @out varchar(max);; select @delimiter =' ' select @s1 = 'This is a string'; select @s1 = 'This is a string ';

Get ConnectionString from app.config in c# [duplicate]

痞子三分冷 提交于 2019-12-19 10:17:28
问题 This question already has answers here : Get connection string from App.config (18 answers) Closed 6 years ago . I have defined my connection String in app.config file <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="CString" connectionString="Data Source=Bilal-PC;Initial Catalog=ATMSoftware;Integrated Security=False; User Id=sa; Password=123" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> Now I want to get it into my C#

How do you print the day name given a day number in SQL Server 2005 using SQL commands?

纵然是瞬间 提交于 2019-12-19 10:06:30
问题 I want to be able to pass in a day number like 1, 2, 3 or 7 and it will return the day name like Sunday, Monday, Tuesday or Saturday. I know there is the option of using a case statement but I would like to do this using SQL commands, would this be at all possible? DECLARE @m VARCHAR SET @m=1 SELECT CASE WHEN @m=1 THEN 'Sunday' END I have already commented on this question when looking for an answer but user @harper suggested that I should submit a new question with a full description. EDIT:

How do I use locking hints so that two parallel queries return non-intersecting results?

╄→尐↘猪︶ㄣ 提交于 2019-12-19 09:56:10
问题 I have an SQL table Tasks with columns Id and State . I need to do the following: find any one task with state ReadyForProcessing , retrieve all its columns and set its state to Processing . Something like (pseudocode): BEGIN TRANSACTION; SELECT TOP 1 * FROM Tasks WHERE State = ReadyForProcessing // here check if the result set is not empty and get the id, then UPDATE Tasks SET State = Processing WHERE TaskId = RetrievedTaskId END TRANSACTION This query will be run in parallel from several

search for a key word in all the Stored Proc's for a given DB?

不想你离开。 提交于 2019-12-19 09:55:19
问题 How to do a global search for a key word in all the Stored Proc's for a given DB? I used the following but I am unable to get the desired results... SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name = 'loadStatus' COLLATE SQL_Latin1_General_CP1_CI_AS ) SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name like '%loadStatus%' COLLATE SQL_Latin1_General_CP1_CI_AS ) Regards -Vas 回答1: Have a look at this link - http://www.sqlservercentral.com

SQL Server INSERT … SELECT Statement won't parse

丶灬走出姿态 提交于 2019-12-19 09:49:56
问题 I am getting the following error message with SQL Server 2005 Msg 120, Level 15, State 1, Procedure usp_AttributeActivitiesForDateRange, Line 18 The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns. I have copy and pasted the select list and insert list into excel and verified there are the same number of items in each list. Both tables an additional primary key field with is not listed in

SQL Server 2005 fill pivot table with 0s

↘锁芯ラ 提交于 2019-12-19 09:44:43
问题 I have this query in SQL Server 2005 (I used the more convenient 2008 insert method for example only) and I need the (null) to be replaced with 0 in the grid output. Anyway to do this? 回答1: You would use the ISNULL() function. See SQL Fiddle SELECT 'lessonid response ->' , isnull([0], 0) as [0] , isnull([1], 0) as [1] , isnull([2], 0) as [2] , isnull([3], 0) as [3] , isnull([4], 0) as [4] FROM ( SELECT lessonid AS 'lessonid response ->' ,ISNULL(response,0) as response ,count(response) AS

How can I query rankings for the users in my DB, but only consider the latest entry for each user?

自闭症网瘾萝莉.ら 提交于 2019-12-19 09:23:45
问题 Lets say I have a database table called "Scrape" possibly setup like: UserID (int) UserName (varchar) Wins (int) Losses (int) ScrapeDate (datetime) I'm trying to be able to rank my users based on their Wins/Loss ratio. However, each week I'll be scraping for new data on the users and making another entry in the Scrape table. How can I query a list of users sorted by wins/losses, but only taking into consideration the most recent entry (ScrapeDate)? Also, do you think it matters that people