sql-server-2005

SQL Server select distinct latest values

泄露秘密 提交于 2020-01-02 03:14:08
问题 I have a table that has a ton of rows (>10K). Most of the rows have duplicate role values associated with the username . What I am trying to do is select rows by distinct AND latest role added by request_id . I almost have it, but the part that is kicking my tail is there are null values in some of the request_id fields because those requests were made before that column was added. I STILL need to include them in the select statement in case a user has not entered another request since the

Can you monitor the execution of an SSIS package, in BIDS, as it runs on the server?

╄→尐↘猪︶ㄣ 提交于 2020-01-02 02:55:30
问题 Although my title states my current goal, I am open to alternative solutions. In short, I have a series of SSIS packages that are scheduled to run on a nightly basis, on our SQL Server machine. Due to various updates that happen in the ether of my corporate-IT, some times these exports brake and the process will stop working, in the middle of the job. To troubleshoot this process, I fire up BIDS on my workstation and restart which ever process fails. This is useful because it's been my

What is an alternative to cursors for sql looping?

孤人 提交于 2020-01-02 02:49:07
问题 Using SQL 2005 / 2008 I have to use a forward cursor, but I don't want to suffer poor performance. Is there a faster way I can loop without using cursors? 回答1: You can do a WHILE loop, however you should seek to achieve a more set based operation as anything in SQL that is iterative is subject to performance issues. http://msdn.microsoft.com/en-us/library/ms178642.aspx 回答2: Here is the example using cursor: DECLARE @VisitorID int DECLARE @FirstName varchar(30), @LastName varchar(30) --

insert char into string at multiple positions sql

旧城冷巷雨未停 提交于 2020-01-02 02:43:28
问题 how would i like to convert accounting GL number 99999999999999999 to 999-99999-99-9999.999 in a query to MSSQL server 2005 i dont need to update the data, just have the STRING be converted on query. Table: GLM_MASTER__ACOUNT Field: Account thanks. 回答1: One more way using STUFF() DECLARE @a varchar(64) SET @a = '99999999999999999' SELECT STUFF(STUFF(STUFF(STUFF(@a, 4, 0, '-'), 10, 0, '-'), 13, 0, '-'), 18, 0, '.') 回答2: You need to use SUBSTRING: SELECT SUBSTRING(account, 1, 3) + '-' +

SQL Server: sys.master_files vs. sys.database_files

大城市里の小女人 提交于 2020-01-02 02:11:04
问题 What is the difference of the sys.master_files and sys.database_files? I have about 20 databases in my instance but when I query the sys.master_files I do not receive any rows. Why? When I query sys.database_files I get the information about the database files concerning the current database. 回答1: sys.master_files : Contains a row per file of a database as stored in the master database. This is a single, system-wide view. sys.database_files : Contains a row per file of a database as stored in

Use comparison signs inside a sql case statement

不羁的心 提交于 2020-01-02 00:00:48
问题 I'm looking for a way to build case statements in a sql select query using less than and greater than signs. For example, I want to select a ranking based on a variable: DECLARE @a INT SET @a = 0 SELECT CASE WHEN @a < 3 THEN 0 WHEN @a = 3 THEN 1 WHEN @a > 3 THEN 2 END I'd like to write it as: DECLARE @a INT SET @a = 0 SELECT CASE @a WHEN < 3 THEN 0 WHEN 3 THEN 1 WHEN > 3 THEN 2 END ...but SQL doesn't let me use the < and > signs in this way. Is there a way that I can do this is SQL 2005, or

Storing SSN/CC data

懵懂的女人 提交于 2020-01-01 19:46:49
问题 I read through quite a few similar questions here on SO but none were in quite the same situation as I am. Previously, user enters in a ton of info including SSN, Spouse SSN, and CC data. When the user completed the process, the info was pushed on PDFs, zipped up (which then got encrypted), and then FTPed back into our server. We saved everything in the DB except SSNs and CC, which were erased when the session died. Now, we need to save that info the database as well for some cases where

How to decode password from sys.syslogins table

人盡茶涼 提交于 2020-01-01 19:16:14
问题 I have a program in which the user needs to login with user name and password. I'm checking the name from the sys.syslogins table in master db. But for the password I receive a string with (probably) coded characters like this (1?????????????). Now what can I do in order to decode that string and take the password in order to compare with the enter it one? 回答1: Try this: SELECT name FROM sys.syslogins WHERE pwdcompare('somepassword', password) = 1 Edited to replace double quotes with single

How to decode password from sys.syslogins table

对着背影说爱祢 提交于 2020-01-01 19:16:04
问题 I have a program in which the user needs to login with user name and password. I'm checking the name from the sys.syslogins table in master db. But for the password I receive a string with (probably) coded characters like this (1?????????????). Now what can I do in order to decode that string and take the password in order to compare with the enter it one? 回答1: Try this: SELECT name FROM sys.syslogins WHERE pwdcompare('somepassword', password) = 1 Edited to replace double quotes with single

Write to file with xp_cmdshell in UTF-8

拜拜、爱过 提交于 2020-01-01 17:27:36
问题 I am creating files with xp_cmdshell like this: SELECT @command = 'echo ' + @fileContent + ' > e:\out\' + @fileName + '.csv' exec master.dbo.xp_cmdshell 'mkdir "e:\out\"' exec master..xp_cmdshell @command The problem is that the file contents is not in UTF-8 and so some special characters are wrong. Can i create the file in UTF-8 encoding? 回答1: You can use the SQLCMD instead the old tecnique as DOS outupt redirect sqlcmd -S ServerName -d DataBaseName -E -o "CSV File Path & Location" -Q "Your