sql-server-2012

How To Split full Name into First Name, Middle Name, Last Name and suffix in TSQL

别等时光非礼了梦想. 提交于 2019-12-13 10:17:00
问题 For E.g I have a FullName Column in table FullName ------------------ Smith Johns Sr James Macoy Krushit J Patel II Sheldon Devid Jeff vandorf Jr Steve Smith I And I want to Result Like |FirstName | Middle Name | lastName | Suffix | |--------------------------------------------| |Smith | NULL | Johns | Null | |James | NULL | Macoy | Null | |Krushit | J | Patel | II | |Sheldon | NULL | Devid | Null | |Jeff | Null | vandorf |Jr | |Steve |Smith | Ronder |I | 回答1: As others have commented, the

Once again: Stored Procedure vs. TV-UDF [closed]

懵懂的女人 提交于 2019-12-13 09:23:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I know, this was discussed several times (most discussions are some years back...). But - looking through these discussions - I get the feeling, that there is a broadly spread common sense which is simply wrong: TV-UDFs are bad in performance. Many people prefer SPs to

carriage return in sql server 2012

元气小坏坏 提交于 2019-12-13 09:15:06
问题 Hey I am using the following query to display the problem list separated by commas. SELECT tt.VrNo, STUFF((select ','+ Er1.ErrorDesc from ( select * from CallRegErrors )as Main left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode WHERE (main.VrNo = tt.VrNo) FOR XML PATH('')) ,1,1,'') AS Problemlist query is giving the output like a,b,c,d etc But my actual requirement is I want to display each error description in a new line like, a b c d etc I tried the following query for it: SELECT tt

how to get data from SQL server ToCityId And FromCityId Bases

别等时光非礼了梦想. 提交于 2019-12-13 08:03:29
问题 I have below query I want to show data fromCityId AND ToCityId . Suppose passenger travel fromCity London toCity Manchester. How do I write query like this, when I use where clause and in , its show me same values in fromcity and tocity Expected results are in below Picture Select vh.VoucharId,fCity.CityName as FromCity, tCity.CityName as ToCity, InDate from VoucharHotel vh inner join City fCity on vh.City = fCity.CityId inner join City tCity on vh.City = tCity.CityId where vh.InDate between

Setting up SSIS Item Template in SQL Server Data Tools for Visual Studio 2012

老子叫甜甜 提交于 2019-12-13 08:02:04
问题 I have created a dtsx file to use as an SSIS package template. I want to be able to use the file as a template by clicking on an open Project in Solution Explorer and selecting Add -> New Item My questions are: How do I save this as a template file? Its currently a .dtsx file. Where do I have to place the file so its in my list of options in the Add New Items dialog? I have seen many conflicting paths and none specifically for SQL Server Data Tools for Visual Studio 2012. I have searched for

SSMA MySql to MsSql Null Value Error

十年热恋 提交于 2019-12-13 08:00:01
问题 The MySQL contains some tables with some zero date time : '0000-00-00 00:00:00'. When using SSMA to migrate the database into MsSql I am facing the error about cannot insert DbNull. This is understandable since neither MySql or MsSql has this field nullable. What I do not understand is that I changed SSMA's Default Projet setting to Replace with a constant all zero-date Not Null columns. The constant I choose is : 1900-01-01. Is there any other settings that must be set? 回答1: The only way I

SQl server duplicate joins issue with different elements

跟風遠走 提交于 2019-12-13 07:56:03
问题 Sorry, I am posting again with one more requirement. can anyone please help: I tried to join with duplicate values but it is not coming as I wanted. DROP TABLE IF EXISTS #TestTable1 DROP TABLE IF EXISTS #TestTable2 CREATE TABLE #TestTable1 ([No] varchar(50),[Value1] float,[Desc] varchar(50)) insert into #TestTable1 ([No],[Value1],[Desc]) Values (N'123953',300.02,N'Extra Pay') ,(N'123953',427.2,N'Basic Hours') ,(N'123953',106.8,N'Basic Hours') ,(N'123953',213.6,N'Basic Hours') ,(N'123953',213

most recent (max) date for every id

余生颓废 提交于 2019-12-13 07:54:42
问题 a = id b = date c = NewestDate For every a, I have b c How can I get the newest date for every set of id's (MY 'a' column)? they don't all have the same end date. So I do need a max for all of them. The data is in myTable, so far i tried: select * into #myTable from myTable select t.a ,t.b ,t.c ,(select max(b) from myTable) as c from myTable t left join #myTable t1 on t.a = t1.a and t.b = t1.b order by a, b The problem with the above code is that in 'c' it is placed the max date of them all,

Embedding a sql case statement into a sql query that is using FOR XML

安稳与你 提交于 2019-12-13 07:43:17
问题 I received some wonderful assistance from a fellow SO user yesterday (see here ) which allowed me to make a great deal of progress towards my goal. Now I'm attempting to establish whether the magical addition that was suggested can be embedded into an existing query that is producing xml output. The existing query is as follows: PROCEDURE [dbo].[CreateLandingPurchaseOrderDetails] -- Add the parameters for the stored procedure here @startDate DATE, @endDate DATE AS BEGIN -- SET NOCOUNT ON

Dynamic SQL Server Variable Parsing Incorrectly from Cursor

試著忘記壹切 提交于 2019-12-13 07:38:52
问题 I'm having trouble parsing a variable from a lookup cursor populated by a lookup table. It is very similar to my previous question here: Dynamic MS SQL Variable Parsing incorrectly But now I'm supplying the @tablename and @columnname from a lookup table, which is causing me to miss the [ and ] around the column names. DECLARE @tableName SYSNAME, @columnName SYSNAME, @col2 SYSNAME, @prompt SYSNAME, @dynSQL varchar(MAX); Declare cLookup CURSOR FOR SELECT * FROM LookupTbl OPEN cLookup FETCH NEXT