tsql

After 13th row Dynamic and in 12th row static values with a formula

泪湿孤枕 提交于 2020-01-25 23:47:12
问题 Below is the SQL Query I used to create as view CREATE VIEW [v_AMP_C] AS SELECT dbo.IC_Raw_In.I_Date, dbo.IC_Raw_In.I_O_P, dbo.IC_Raw_In.I_O_H, dbo.IC_Raw_In.I_O_L, dbo.IC_Raw_In.I_C_O, dbo.AMPS12_C.AMPS12_C FROM dbo.IC_Raw_In INNER JOIN dbo.AMPS12_C ON dbo.IC_Raw_In.I_Serial = dbo.AMPS12_C.i_serial and the data is imported to this table by useing a bulk insert dbo.IC_Raw_In and data type are Money except I_Date. Then when i ran the query i.e,. select * from v_AMP_C i got the below as output

TSQL - Looking for code clarification

♀尐吖头ヾ 提交于 2020-01-25 21:16:28
问题 This is the code I used and the result is posted below: SELECT * FROM (SELECT P.ProductID, PC.Name, ISNULL (P.Color, 'uncolored') AS color FROM SalesLT.ProductCategory AS PC JOIN SalesLT.Product AS P ON PC.ProductCategoryID = P.ProductCategoryID ) AS PPC PIVOT (COUNT (ProductID) FOR Color IN ([Red],[Blue],[Silver],[Black],[Yellow],[Grey],[Multi],[Uncolored])) AS pvt ORDER BY Name; I didn't request the query to provide me the name, could someone explain me how this 'name' thing popped up in

How to increase counter in select

◇◆丶佛笑我妖孽 提交于 2020-01-25 21:12:28
问题 I have this kind of situation - Column A 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 I want something like this- Column A Column B 1 1 0 1 0 1 0 1 1 2 0 2 0 2 0 2 0 2 1 3 0 3 1 4 0 4 0 4 1 5 0 5 Its like for each occurance of 1 in column A we are increasing the number in column B by one. I want to have this in a select. I can't use loop for this. I am using SQL-Server 2008 R2. Can anyone please give me idea how it can done. Thanks in advance. 回答1: With a cte and window function Row_Number()... However, I

Create missing months dynamically from group on date field [duplicate]

夙愿已清 提交于 2020-01-25 20:34:26
问题 This question already has answers here : SQL select, pad with chronological missing months (3 answers) Closed 4 years ago . In the following SQL i'm trying to insert rows to fill in the missing months in the results. The solution is very close thanks to post SQL select, pad with chronological missing months But yet this code runs gr8 but still have missing months, issue is how to join/union the temp table DECLARE @StartDate DATETIME = dateadd(m,-12,getdate()), @EndDate DATETIME = getdate(),

MSSQL Select Random in Large Data

假装没事ソ 提交于 2020-01-25 16:21:28
问题 I have a table that has more than 1 million records and I want to select random rows from this table, but not among all records - only select Random rows from results matching certain conditions. Performance is very important , so I can NOT use ordering by NEWID and then select first item. The table structure is some thing like this: ID BIGINT Title NVARCHAR(100) Level INT Point INT Now, I wrote a query like: with tmp_one as ( SELECT R.Id as RID FROM [User] as U Inner Join [Item] as R On R

MSSQL Select Random in Large Data

让人想犯罪 __ 提交于 2020-01-25 16:20:30
问题 I have a table that has more than 1 million records and I want to select random rows from this table, but not among all records - only select Random rows from results matching certain conditions. Performance is very important , so I can NOT use ordering by NEWID and then select first item. The table structure is some thing like this: ID BIGINT Title NVARCHAR(100) Level INT Point INT Now, I wrote a query like: with tmp_one as ( SELECT R.Id as RID FROM [User] as U Inner Join [Item] as R On R

How to make total?

给你一囗甜甜゛ 提交于 2020-01-25 12:51:06
问题 Using SQLSERVER 2000 How to make a total of intime value Table 1 InTime 02:00:48 22:00:22 ....., Intime Datatype is varchar 02:00:12 - (HH:MM:SS) Before I tried in access 2003 select format( Int(24*sum(Intime)), '0') & format( sum(Intime) , ':ss' ) AS totaltime from table1 Above Query is working perfectly in Access 2003 How to make a total of Intime in sql? Expected Output Intime 24:01:00 So on..., Need Query help 回答1: try this: CREATE TABLE #Table1 ( inTime varchar(8) ) SET NOCOUNT ON INSERT

How to make total?

孤者浪人 提交于 2020-01-25 12:50:09
问题 Using SQLSERVER 2000 How to make a total of intime value Table 1 InTime 02:00:48 22:00:22 ....., Intime Datatype is varchar 02:00:12 - (HH:MM:SS) Before I tried in access 2003 select format( Int(24*sum(Intime)), '0') & format( sum(Intime) , ':ss' ) AS totaltime from table1 Above Query is working perfectly in Access 2003 How to make a total of Intime in sql? Expected Output Intime 24:01:00 So on..., Need Query help 回答1: try this: CREATE TABLE #Table1 ( inTime varchar(8) ) SET NOCOUNT ON INSERT

SSIS datetime conversion issue between excel and sql

梦想与她 提交于 2020-01-25 12:48:28
问题 if I bang my head on my desk 1 more time I might be gone forever. Source: Excel Data: 2012-10-05T11:14:00 Conversion: 2012-10-05T11:14:00 in Excel to string [DT_STR] Destination: SQL Column Data Type: datetime I keep getting the following errors: [PostBindInspectionsBucket [20]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Invalid

update statement not executing

此生再无相见时 提交于 2020-01-25 12:29:12
问题 I am trying to write an UPDATE query that can check for a null value in one of the fields. I have three conditions, two are mandatory, of three fields. itemCode and itemCheckDigit will always exist, itemSuffix is possibily Null. There may be multiple records where itemCode and itemCheckDigit together are equal to other records, itemSuffix is the unquie identifier, only one instance will exist though where itemSuffix is Null and it will never be duplicated. UPDATE item SET itemImageFileName =