Tag: sql-server-2012

Subtracting rows depending on values of another column

I have two tables purchase, I want to subtract purchase date. depending on Customer ID, there are repeating customer ID’s, so I want to subtract purchase date of Customer ID 105 and 105, 108 and 108 etc. I have the following code, but it is subtracting each purchase date from the next purchase date SELECT […]

T-SQL how to repopulate fulltext index on a View

I created a fulltextindex on some computed columns in my view, which had been created with schemabinding and given a unique clustered index so it could be fulltext indexed. The computed columns concatenate several columns together with a space between them. Afterwards I noticed that there were nulls in some of these concatenated columns, which […]

MERGE statement issue

I have a table [ExistingTable] with three columns: ID, Value and Date +—-+——————+ | ID | Value | Date | +—-+——————+ | 1 | 100 |2016-01-01| | 1 | 200 |2016-01-01| | 1 | 300 |2016-01-01| | 2 | 200 |2016-01-01| | 2 | 300 |2016-01-01| +—-+——————+ and the second table, [NewTable] +—-+————+ | ID […]

Left Outer join not returning expected resultSet

I have these two tables #TABLE1# ##CompanyName## ##PrimaryKey## DELL 1 DELL CALIFORNIA 2 DELL SAN FRANCISCO 3 DELL LOS ANGELES 4 IBM 5 GOOGLE 6 #TABLE2# ##ParentComp## ##ParentPrimaryKey## ##ChildComp## ##ChildPrimaryKey## DELL 1 DELL CALIFORNIA 2 DELL CALIFORNIA 2 DELL SAN FRANCISCO 3 DELL CALIFORNIA 2 DELL LOS ANGELES 4 Now the expected table is shown […]

conversion varchar data type to a datetime data type resulted in an out-of-range

need help trying to get from the database some info and i want to call only the persons of today and i have the error the conversion of a varchar data type to a datetime data type resulted in an out-of-range value. TRY_CONVERT isn’t a recognized function select DTC.PrimerNombre+ ‘ ‘ + DTC.SegundoNombre+’ ‘+ DTC.PrimerApellido […]

Connect JavaScript and Ms Sql

Here is scope of the project I know enough html and CSSs to build a website. I know enough of MS sql to build stored procedures and complicated quires. I’m trying to bring everything to new next level The question is very broad but I need some navigation. How do I build web based app […]

SQL Server time sheet calculation

I have a time punch program the outputs the data set below. RECTYP_43 are the (1) in and (2) out punches. I need a query to look at the look at the LOGINDATE_43 and LOGINTIME_43 and the RECTYPE_43 and get the difference between 1 and 2. I thought this would be easier than it has […]

SSMS (MS SQL Server Management Studio) save job into comma delimited csv

I am really new in MS SQL Server Management. I create job.. Then I choose advanced in job steps..and choose to save as test.csv. SELECT T0.U_Scid as ‘id’, T3.U_Boarding as ‘start’, … T3.U_Boarding as ‘end’, T2.Name as ‘service_classification’, T5.U_Type as ‘equipment’ FROM [XXX].[dbo].[@COR_SC_EQUIP] T5,[XXX].[dbo].[@COR_SC_GENERAL] T3, [XXX].[dbo].[@COR_SC_HEADER] T0 INNER JOIN [XXX].[dbo].[OSCS] T1 on T0.U_Status = T1.statusID […]

What is the best way to check if a column contains any of the keywords

I have table of keywords Keywords: KeyID | Keyword 1 Small 2 Medium 3 Large 4 XXLarge Then I have another table “Logs” that has over 100 000 records. Logs: LogId | Description 1 blah blah.. Medium blah 2 dsdms Large whatever I would like to add another column as KeyId in Logs table and […]

sql scalar-valued functions incredibly slow

SQL Server 2012 – I have a view (complicated) and one of the columns needs to have anything non-numeric stripped out. The following works to a point; STUFF(dbo.campaign_tracking_clicks.tt_cpn, 1, PATINDEX(‘%[0-9]%’, dbo.campaign_tracking_clicks.tt_cpn) – 1, ”) AS emailerid I get an error if anything but numbers are at the end of the value. I have a scalar-valued […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.