求一个sqlserver函数,根据多个列名称获得对应的列ID

求一个sqlserver函数,根据多个列名称获得对应的列ID,第1张

select ID from 表名 where name in ('李四,'张三') //还可以加入",'王五'"等。

或者:

select ID from 表名 where name = '李四' or name = '张三'

mysql> select DATE_FORMAT('1997-10-04 22:23:00', '%Y/%m ');

+----------------------------------------------+

| DATE_FORMAT('1997-10-04 22:23:00', '%Y/%m ') |

+----------------------------------------------+

| 1997/10 |

+----------------------------------------------+

一、查看实例名时可用

1、服务—SQL Server(实例名),默认实例为(MSSQLSERVER)

或在连接企业管理时-查看本地实例

2、通过注册表

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SQL

Server/InstalledInstance

3、用命令

sqlcmd/osql

sqlcmd -L

sqlcmd -Lc

osql

-L

获取可用实例,以下举一个例子,根据自己情况改

复制代码

代码如下:

DECLARE @Table TABLE ( instanceName

sysname NULL)

insert @Table EXEC sysxp_cmdshell 'sqlcmd -Lc'

--LEFT(@@serverName,CHARINDEX('/',@@serverName+'/')-1) 替代为本机名就行了 ,

根据实例命名规则判断

SELECT FROM @Table WHERE instanceName LIKE LEFT( @@serverName , CHARINDEX

( '/' , @@serverName + '/' )- 1)+ '%'

二、

--1

SELECT

SERVERPROPERTY('InstanceName')

--2

sp_helpserver

--3

select

@@SERVERNAME

--4

SELECT FROM

SYSSYSSERVERS

--5

SELECT FROM

SYSSERVERS

三、

EXECUTE xp_regread

@rootkey='HKEY_LOCAL_MACHINE',

@key='SOFTWARE/Microsoft/Microsoft SQL

Server/Instance Names/SQl',

@value_name='MSSQLSERVER'

四、

Select Case

When SERVERPROPERTY ('InstanceName') Is Null Then

@@SERVERNAME

Else SERVERPROPERTY ('InstanceName')

End

五、在本地或网络得到所有实例名

1、You can do with registry reading , like my code

复制代码

代码如下:

using System;

using MicrosoftWin32;

namespace SMOTest

{

class Program

{

static void

Main()

{

RegistryKey rk =

RegistryLocalMachineOpenSubKey(@"SOFTWARE/Microsoft/Microsoft SQL

Server");

String[] instances =

(String[])rkGetValue("InstalledInstances");

if (instancesLength

> 0)

{

foreach (String element in

instances)

{

if (element ==

"MSSQLSERVER")

ConsoleWriteLine(SystemEnvironmentMachineName);

else

ConsoleWriteLine(SystemEnvironmentMachineName + @"/"

+ element);

}

}

}

}

}

2、You can use SQLDMOdll to retrieve the list of SQL

Server instances The SQLDMOdll can be found from the "C:/Program

Files/Microsoft SQL Server/80/Tools/Bin" folder Refer this assembly in your

project and the following snippet would return a List Object containing the sql

server instances

复制代码

代码如下:

public static List GetSQLServerInstances()

{

NameList sqlNameList = null;

Application app = null;

var sqlServers = new List();

try

{

app = new

ApplicationClass();

sqlNameList = appListAvailableSQLServers();

foreach

(string sqlServer in

sqlNameList)

sqlServersAdd(sqlServer);

}

catch(Exception

ex)

{

//play with the exception

}

finally

{

if (sqlNameList

!= null)

sqlNameList = null;

if (app != null)

app =

null;

}

return sqlServers;

}

以上就是关于求一个sqlserver函数,根据多个列名称获得对应的列ID全部的内容,包括:求一个sqlserver函数,根据多个列名称获得对应的列ID、sql如何获取一列日期的年份和月份、如何查看和获取SQL Server实例名等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9459920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存