sql-server-2008-r2

SQL Split Function and Ordering Issue?

做~自己de王妃 提交于 2019-12-01 18:07:21
I have the following Split function, ALTER FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1)) returns @temptable TABLE (items varchar(8000)) as begin set @String = RTRIM(LTRIM(@String)) declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)<1 or @String is null return while @idx!= 0 begin set @idx = charindex(@Delimiter,@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)>0) insert into @temptable(Items) values(@slice) set @String = right(@String,len(@String) - @idx) if len(@String) = 0 break end return end When

SQL Split Function and Ordering Issue?

喜夏-厌秋 提交于 2019-12-01 17:31:28
问题 I have the following Split function, ALTER FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1)) returns @temptable TABLE (items varchar(8000)) as begin set @String = RTRIM(LTRIM(@String)) declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)<1 or @String is null return while @idx!= 0 begin set @idx = charindex(@Delimiter,@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)>0) insert into @temptable(Items) values(

get the text of a stored procedure into a variable in SQL Server

旧城冷巷雨未停 提交于 2019-12-01 17:23:35
I want to loop through several stored procs and extract one string form each of them to use in another procedure (basically the 4-part remote server string) So I can get the stored procs list from SysObjects (with Type = P) into a table, then I can loop or cursor through that table variable calling sp_helptext on each one. But how can I get the text result of sp_helptext into a variable so I can do a CharIndex on the word ' BOCTEST ' etc? Is there a table like sys.procedures that stores the text. The portable way is to use the ANSI/ISO view INFORMATION_SCHEMA.ROUTINES , but you'll only get the

SQL SELECT Previous MMYY as varchar(4)

血红的双手。 提交于 2019-12-01 14:48:23
Dearest genius StackOverflow friends, I'm in the need of creating a view that will always give me data in the WHERE clause for "Period" looking for the previous Month and Year ( MMYY ) in varchar(4) format. Example: Today is March 3rd, 2015, so what I need is for Period to be 0215 . SELECT stuff FROM table WHERE period = '0215' How do I automatically generate the '0215' in the view so I'm always seeing last months data? Any assistance would be greatly appreciated. Try this expression: SELECT STUFF(CONVERT(VARCHAR(10), DATEADD(MONTH, -1, GETDATE()), 101), 3, 6, '') Use this: ;WITH PrevMonth AS

SQL Server 2008 R2: Delete duplicate rows from tables containing in view

喜你入骨 提交于 2019-12-01 14:38:44
--Creating Table dup1 CREATE TABLE dup1 ( cola VARCHAR(10), colb VARCHAR(10) ); --Insertion of records INSERT INTO dup1 VALUES('1','2'); INSERT INTO dup1 VALUES('1','2'); INSERT INTO dup1 VALUES('1','3'); INSERT INTO dup1 VALUES('1','4'); INSERT INTO dup1 VALUES('1','5'); --Creating Table dup2 CREATE TABLE dup2 ( cola VARCHAR(10), colb VARCHAR(10) ); --Insertion of records INSERT INTO dup2 VALUES('1','2'); INSERT INTO dup2 VALUES('1','2'); INSERT INTO dup2 VALUES('2','3'); INSERT INTO dup2 VALUES('2','4'); INSERT INTO dup2 VALUES('1','5'); --Creating View CREATE VIEW V_Dup as SELECT * FROM

PDO rowCount() works on MySQL but not in SQL Server 2008 R2

南笙酒味 提交于 2019-12-01 14:13:33
I have a problem when I get number of rows in SQL Server 2008 because my code works fine using MySQL but not in SQL Server. $sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile FROM sa_users U INNER JOIN sa_profiles P ON P.Id = U.Profile WHERE User = :user AND Pass = :pass"; $result = $this->dbConnect->prepare($sql) or die ($sql); $result->bindParam(':user',$this->data['username'],PDO::PARAM_STR); $result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR); if (!$result->execute()) { return false; } $numrows = $result->rowCount(); $jsonLogin = array(); var_dump($numrows);

SQL SELECT Previous MMYY as varchar(4)

寵の児 提交于 2019-12-01 13:30:03
问题 Dearest genius StackOverflow friends, I'm in the need of creating a view that will always give me data in the WHERE clause for "Period" looking for the previous Month and Year ( MMYY ) in varchar(4) format. Example: Today is March 3rd, 2015, so what I need is for Period to be 0215 . SELECT stuff FROM table WHERE period = '0215' How do I automatically generate the '0215' in the view so I'm always seeing last months data? Any assistance would be greatly appreciated. 回答1: Try this expression:

PDO rowCount() works on MySQL but not in SQL Server 2008 R2

南楼画角 提交于 2019-12-01 13:26:33
问题 I have a problem when I get number of rows in SQL Server 2008 because my code works fine using MySQL but not in SQL Server. $sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile FROM sa_users U INNER JOIN sa_profiles P ON P.Id = U.Profile WHERE User = :user AND Pass = :pass"; $result = $this->dbConnect->prepare($sql) or die ($sql); $result->bindParam(':user',$this->data['username'],PDO::PARAM_STR); $result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR); if (!$result-

SQL Server 2008 R2: Prepare Dynamic WHERE Clause

梦想的初衷 提交于 2019-12-01 12:56:34
问题 I have the following stored procedure with four parameters. Stored procedure spTest : CREATE PROCEDURE spTest @Name varchar(20) = '', @Address varchar(100) = '', @City varchar(50) = '', @Pin varchar(50) = '' AS DECLARE @DynamicWhere varchar(max) DECLARE @Query varchar(max) /* Here I want to prepare a dynamic where clause for all possibilities */ SET @Query = 'SELECT * FROM Test_Table '+ @DynamicWhere +''; EXECUTE(@Query); GO Well I am preparing it like this: IF @Name = '' AND @Address = ''

Git Fetch Error with UNC

假如想象 提交于 2019-12-01 12:46:56
问题 I have a GIT backup script that runs perfectly when executed from command line (it's a daily backup of our main GIT rep): @echo off rem -- Set Parameters rem -- daliy GIT backup REM Get DATE set mm=%Date:~4,2% set dd=%Date:~7,2% set yy=%Date:~10,4% set TODAY=%yy%%mm%%dd% for /f %%a in ('date /t') do set DAY=%%a if %DAY%==Sun goto :weekend if %DAY%==Sat goto :weekend goto :weekday :weekend :: No backup after weekends echo %day% exit :weekday :: Backup during weekdays REM Connect to share REM