Tag: tsql

Turkish Characters aren't shown in db when i use dynamic SQL Query

I’ve a problem that is about Turksih Characters I’m using dynamic sql query,when i saw the table Turkish Character is shown in English Charter etc. ‘s’ is seen instead of’ş’. When I didn’t use Dynamic Query, I haven’t any problem. But I have to use Dynamic Query. My query is: declare @sql nvarchar(max) SET @Sql […]

LEFT JOIN with subquery and accessing main table columns in select clause

I have an insert statement like the following which gets sytax error of “the multi-part identifier “t2.Col1″ could not be bound.”. I over simplified the statement and it looks like below: INSERT INTO dbo.T1 ( Col1, Col2, Col3 ) SELECT t2.Col1, SUBSTRING(aCase.CaseColumn, 0, CHARINDEX(‘%’, aCase.CaseColumn)), –I expect this line gets the value “2” SUBSTRING(aCase.CaseColumn, CHARINDEX(‘%’, […]

Get sql text of a UDT

When creating a function or a trigger, you can find its creation command in sys.sql_modules But what i cannot seem to find is the same for UDTs. When I create a type like this CREATE TYPE dbo.UserIds AS TABLE (value int NOT NULL PRIMARY KEY); it doesnt show up in sys.sql_modules. The only information I […]

T-SQL convert inner joined table's rows as columns

select a.code, b.translationName from Funds a inner join Translations b ON a.code = b.code where a.code= ‘xyz123’ This query returns a two-row, two-column result as below: code translationName ————————————— xyz123 ‘Fund’s chineseName’ xyz123 ‘Fund’s JapaneseName’ Is there a way to return the result as code translatonName1 translationName2 xyz123 ‘Fund’s chineseName’ ‘Fund’s JapaneseName’ btw, there is […]

SQL Inserting into table from temp table, and having ouput id inserted into temp table

This question is really two parts. The first part is just inserting into a real table with a temp table and having the output inserted into another temp table is not working. Here is the example. Insert Into student Output INSERTED.* Into #StudentsOutput Select * From #StudentsResult The error from above when I hover over […]

Large Data Set Concatenate Values into Query

I have a view with literally millions of rows, this times out when running it for everything but can do selects within it to pull back snapshots of data. VIEW A (over 5000000 rows – Times out when running for everything) I’m trying to concatenate the Criteria name and KeyDescription2 based on column 0 and […]

TSQL – Reduce the number of records with intelligence – patterns (crash impact data)

I have some data that contains data from measurements from crash impact tests. When the object is not moving the measurements contain much rows of the same data, when the object is moving and shaking it can register quite big fluctuations. Problem: I have hundreds of millions of lines of this data and to use […]

SQL Query to identify records applicable for a distinct set of data

I have the following query that returns the result as shown below the query. However, I need only a subset of this data. I am interested in fetching DocumentIDs that are associated to RegionID value of 2 ONLY and not associated to any other region. SELECT D.DocumentID, R.RegionID, COUNT(*) AS NUMOFPLANTSBYREGION FROM Document D INNER […]

If NOT EXISTS in SQL not function

I put this in the SQL Query editor of SQL Server 2008 and doesn’t work: If not EXISTS (Select * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= ‘dbo’ AND TABLE_NAME=’PK01′) CREATE TABLE [dbo].[‘PK01’] (Articulo varchar(MAX),Referencia varchar(MAX),Lote varchar(MAX),Cantidad Int,Ubicacion varchar(MAX)); INSERT INTO [UBICACIONES].[dbo].[‘PK01’] (Articulo,Referencia,Lote,Cantidad,Ubicacion)VALUES (‘998′,’kk’,’ll’,0,’pp’) else UPDATE [UBICACIONES].[dbo].[‘PK01’] Set Cantidad = (Cantidad + 23) WHERE Articulo LIKE ‘998’ Error […]

Inserting data into a temp table from an open query

I’ve looked online and you can not drop variables into an open query so easily so I modified my query and it says the #TempOT temp table is “Invalid object name ‘#TempOT’.” What am I doing wrong that is causing the temp table not to get populated? BEGIN IF OBJECT_ID(‘tempdb..#TempOT’) IS NOT NULL BEGIN DROP […]

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