sql-server-2005

Reason for using @@identity rather than scope_identity

本秂侑毒 提交于 2020-01-21 06:26:21
问题 On a SQL Server 2005 database, one of our remote developers just checked in a change to a stored procedure that changed a "select scope_identity" to "select @@identity". Do you know of any reasons why you'd use @@identity over scope_identity? 回答1: @@IDENTITY will return the last identity value issued by the current session. SCOPE_IDENTITY() returns the last identity value in the current session and same scope. They are usually the same, but assume a trigger is called which inserted something

How to find out user name and machine name to access to SQL server

旧巷老猫 提交于 2020-01-21 01:42:19
问题 My work company has a MSSQL server 2005. I have two questions about finding out current log user and any way to send out a warning message: First question is if there is any T-SQL or SP available to find out current login user name and machine name. If the user is using SQL server sa name to remotely access to SQL server, is there any way to find out that user's windows name (the name to log to the windows)? My next question is that if I can get the user name or id, is there any way to send

How to display the date as mm/dd/yyyy hh:mm Am/PM using sql server 2008 r2?

别来无恙 提交于 2020-01-20 18:44:13
问题 My sample query is SELECT D30.SPGD30_LAST_TOUCH_Y from CSPGD30_TRACKING D30 My given date format is like "2013-01-01 00:00:00.000" . I need to convert this date format to "mm/dd/yyyy hh:mm AM/PM" . Do you have any idea about that? 回答1: I think there is no single format to give them both. Try this using Convert ; Sql-Demo declare @mydate datetime = getdate() select convert(varchar(10),@mydate, 101) + right(convert(varchar(32),@mydate,100),8) | COLUMN_0 | ---------------------- | 02/22/2013 9

How to display the date as mm/dd/yyyy hh:mm Am/PM using sql server 2008 r2?

若如初见. 提交于 2020-01-20 18:42:49
问题 My sample query is SELECT D30.SPGD30_LAST_TOUCH_Y from CSPGD30_TRACKING D30 My given date format is like "2013-01-01 00:00:00.000" . I need to convert this date format to "mm/dd/yyyy hh:mm AM/PM" . Do you have any idea about that? 回答1: I think there is no single format to give them both. Try this using Convert ; Sql-Demo declare @mydate datetime = getdate() select convert(varchar(10),@mydate, 101) + right(convert(varchar(32),@mydate,100),8) | COLUMN_0 | ---------------------- | 02/22/2013 9

How to display the date as mm/dd/yyyy hh:mm Am/PM using sql server 2008 r2?

狂风中的少年 提交于 2020-01-20 18:42:24
问题 My sample query is SELECT D30.SPGD30_LAST_TOUCH_Y from CSPGD30_TRACKING D30 My given date format is like "2013-01-01 00:00:00.000" . I need to convert this date format to "mm/dd/yyyy hh:mm AM/PM" . Do you have any idea about that? 回答1: I think there is no single format to give them both. Try this using Convert ; Sql-Demo declare @mydate datetime = getdate() select convert(varchar(10),@mydate, 101) + right(convert(varchar(32),@mydate,100),8) | COLUMN_0 | ---------------------- | 02/22/2013 9

How can I make a primary key as AUTOINCREMENT

时光毁灭记忆、已成空白 提交于 2020-01-20 05:00:07
问题 I have table in Database and the primry key is 'ID', Just I want to ask how can I make it AUTOINCREMENT I know that's esay Q, but I dont know how can I do it. thanks 回答1: There is a property "Identity Specification". Expand that one, you can chose Increment value, and Increment Seed 回答2: In Sql Server define the column like this... [PrimaryID] [int] IDENTITY(1,1) NOT NULL Then you can add a constraint making it the primary key. 回答3: MySQL: http://dev.mysql.com/doc/refman/5.0/en/example-auto

sql query with self join

眉间皱痕 提交于 2020-01-17 05:11:22
问题 Given a table (TableA) that contains the following data; Id Date Status RecordId 1 01/06/11 2 REC001 2 01/06/11 2 REC002 3 01/06/11 2 REC003 4 01/07/11 1 REC001 How can I return all records with a status of 2 except records with a given RecordId where a status of 2 is followed by a record of 1 at a later date (and there are no further records with a status of 2. So for example, the query should return REC002 and REC003 as REC001 had a status of 2 in the past, but that was superseeded by

How to turn on the FULLTEXT mode on SQL Server 2005

旧城冷巷雨未停 提交于 2020-01-17 03:33:06
问题 I'm currently trying to create FULLTEXT indexes into my database (Microsoft SQL Server 2005). First I want to create the catalog: USE [AspDotNetStorefront] GO EXEC sp_fulltext_database 'enable' GO CREATE FULLTEXT CATALOG searchcatalog GO But that doesn't work, the result is this: Msg 7609, Level 17, State 100, Line 1 Full-Text Search is not installed, or a full-text component cannot be loaded. I'm running on Windows XP, SQL Server Express 9.0.4053 and I have SQL Server Management Studio

How do I provide a string with a list of values to an “IN” statement

大憨熊 提交于 2020-01-17 03:27:49
问题 I am creating a string that is a list of comma-delimitted values by looping through the selections in a CheckBoxList. I am able to display this value, so I know that it is creating what I expect. I am attempting to pass this list to an IN statment in a SELECT query: SelectCommand="SELECT ThisDate, DATEPART(dw, ThisDate) AS Expr1 FROM fbCalendar WHERE (ThisDate >= @ThisDate) AND (ThisDate <= @ThisDate2) AND (DATEPART(dw, ThisDate) IN (@TheseDays))" <asp:ControlParameter ControlID="Label1" Name

Two query in single result table?

只谈情不闲聊 提交于 2020-01-17 03:12:09
问题 I am newbie in SQL Server 2008.There is a Proc.In this Proc, I have two select statements.When I execute my Proc, I will get results in two table which I accepted. But I want to this return in single table. My Proc - ALTER PROC [GetPaymentGateway] @CompanyID VARCHAR(3), @ChannelType varchar(15)=null AS IF @ChannelType='BODC' OR @ChannelType='BO-DC' BEGIN SELECT [card_name], [card_type], [BODC_Amount], [BODC_Amount_Type], PGM.PG_Type FROM credit_card_master CCM INNER JOIN PaymentGateway_master