tsql

Combining two sql columns with delimited data by collating into a single column with delimited data

自作多情 提交于 2021-01-29 05:40:45
问题 I have two sql columns each with delimited data that I want to collate and combine into a single delimited column. The number of items in the column is variable for each row. However there will always be a matching number of items between the two columns of each row. For Example... ******************************* ORIGINAL SQL TABLE ******************************* value * unit ******************************* 4 ; 5 * mg ; kg 50 * mg 7.5 ; 325 * kg ; mg 100 ; 1.5 ; 50 * mg ; g ; mg *************

Get Total CPU # via WMI or T-SQL

旧街凉风 提交于 2021-01-29 05:00:28
问题 I don't want the list of all process, just a total percentage like you would see in windows taskmanager. I will be using this information via coldfusion, but i am having all kinds of problems just trying to find a total number of current cpu usage. I don't care if it comes from wmi or t-sql, i just want a total number for which i will be using to populate a gauge chart that via ajax will be showing my current cpu usage percentage... Thank You... 回答1: You can use the Win32_PerfRawData_PerfOS

Dynamic SQL with C# SqlCommand

痞子三分冷 提交于 2021-01-29 04:46:12
问题 I'd like to create a dynamic SQL query with c#'s SqlCommand where even the table is a parameter, so as to avoid injection attempts. Like below: comm.CommandText = "SELECT * FROM @tbl WHERE cond=@cond"; comm.Parameters.AddWithValue("tbl","TABLENAME"); comm.Parameters.AddWithValue("cond","CONDITION"); However, I have found that this is not allowed. I've looked into using Dynamic SQL with an execute, but that seems to be only for stored procedures. Can I use Dynamic SQL with an Execute using

Dynamic SQL Server query

霸气de小男生 提交于 2021-01-29 04:26:03
问题 I am writing a dynamic insert query in a stored procedure. I am receiving the column names as parameter to my stored procedure. For example, I have an Employee table with EmployeeId and EmployeeName columns. I need to append EMP_ before each employee name while inserting the data into Department table from Employee table. Non-dynamic query looks like this. INSERT INTO Department(EmployeeId, EmployeeName) SELECT EmployeeId, 'EMP_' + EmployeeName FROM Employee If I write a dynamic insert SET

What's mean of the “T(C)”? when I query xml in sql server 2008

£可爱£侵袭症+ 提交于 2021-01-29 01:36:27
问题 What's mean of the "T(C)"? DECLARE @xml XML ='<root><id>1</id><id>2</id><id>3</id><id>4</id></root>' SELECT T.C.value('(text())[1]','varchar(20)') FROM @xml.nodes('/root/id') AS T(C) Note:can you give me a perfessional url,I want to see carefully. thx very much. 回答1: From MSDN Nodes() Function syntax is nodes (XQuery) as Table(Column) Table(Column) Is the table name and the column name for the resulting rowset. 来源: https://stackoverflow.com/questions/27919534/whats-mean-of-the-tc-when-i-query

How to update and add new records at the same time

落爺英雄遲暮 提交于 2021-01-28 22:21:47
问题 I have a table that contains over than a million records (products). Now, daily, I need to either update existing records, and/or add new ones. Instead of doing it one-by-one (takes couple of hours), I managed to use SqlBulkCopy to work with bunch of records and managed to do my inserts in the matter of seconds, but it can handle only new inserts. So I am thinking about creating a new table that contains new records and old records; and then use that temporary table (on the SQL end) to update

Storing single form table questions in 1 or multiple tables

蓝咒 提交于 2021-01-28 21:17:35
问题 I have been coding ASP.NET forms inside web applications for a long time now. Generally most web apps have a user that logs in, picks a form to fill out and answers questions so your table looks like this Table: tblInspectionForm Fields: inspectionformid (either autoint or guid) userid (user ID who entered it) datestamp (added, modified, whatever) Question1Answer: boolean (maybe a yes/no) Question2Answer: int (maybe foreign key for sub table 1 with dropdown values) Question3Answer: int

How do I make truncate log script as dynamic SQL in SQL Server?

拟墨画扇 提交于 2021-01-28 21:16:20
问题 I am using the below script to truncate the log files of a database. But I have to execute the below script results in separate window due to this I am not able to schedule the jobs . SET NOCOUNT ON SELECT 'USE [' + d.name + N']' + CHAR(13) + CHAR(10) + 'DBCC SHRINKFILE (N''' + mf.name + N''' , 0, TRUNCATEONLY)' + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10) FROM sys.master_files mf JOIN sys.databases d ON mf.database_id = d.database_id WHERE d.database_id > 4 and mf.type_desc = 'LOG' Expected O

how to call web service from t-sql

僤鯓⒐⒋嵵緔 提交于 2021-01-28 18:17:50
问题 I'm using below code to call a web service, but its returning empty value. Please help me on this: Declare @Object as Int; Declare @ResponseText as Varchar(8000); Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT; Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://usadc-vsbbmd02:8085/rest/api/latest/plan/EP-AR','false' Exec sp_OAMethod @Object, 'send' Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT Select @ResponseText Exec sp_OADestroy @Object 回答1: You should use SQLCLR or an

Can calculated column be used in another calculated column?

白昼怎懂夜的黑 提交于 2021-01-28 14:50:35
问题 SELECT ExchangeRatePrice = CASE pp.Price WHEN NULL THEN 0 ELSE (CASE WHEN c.CurrencyId = 1 THEN pp.Price ELSE CONVERT(DECIMAL(9, 2), (pp.Price * c.ExchangeRate)) END) END , price as OriginalPriceInDB, 10 * Price as CalculatedPrice, c.currencyid as Currency FROM ProductPrice pp, currency c alt text http://img682.imageshack.us/img682/3692/exchangerate.png I want calculated column (ExchangeRatePrice) to use in CalculatedPrice. Can I use it straight of I need to convert it again? I have used 10 *