sql-server-2005

Using cast in insert statement

心不动则不痛 提交于 2021-02-08 14:16:38
问题 I am inserting some raw data into a table in MS SQL 2005 from excel. Some of these data are not formatted correctly ie the amount colum is formatteT as a number 12345 whereas i need to be like 123.45 so i use this CAST(TRANSACTION_HISTORY.AMOUNT AS decimal) / 100 to convert it correctly. However is there a way to use the cast in an insert statement?? thanks 回答1: You can use CAST in any kind of statement(Insert, update, delete, select) where you use data. Insert into table1 values( CAST(col1

Using cast in insert statement

岁酱吖の 提交于 2021-02-08 14:14:21
问题 I am inserting some raw data into a table in MS SQL 2005 from excel. Some of these data are not formatted correctly ie the amount colum is formatteT as a number 12345 whereas i need to be like 123.45 so i use this CAST(TRANSACTION_HISTORY.AMOUNT AS decimal) / 100 to convert it correctly. However is there a way to use the cast in an insert statement?? thanks 回答1: You can use CAST in any kind of statement(Insert, update, delete, select) where you use data. Insert into table1 values( CAST(col1

Using cast in insert statement

此生再无相见时 提交于 2021-02-08 14:12:23
问题 I am inserting some raw data into a table in MS SQL 2005 from excel. Some of these data are not formatted correctly ie the amount colum is formatteT as a number 12345 whereas i need to be like 123.45 so i use this CAST(TRANSACTION_HISTORY.AMOUNT AS decimal) / 100 to convert it correctly. However is there a way to use the cast in an insert statement?? thanks 回答1: You can use CAST in any kind of statement(Insert, update, delete, select) where you use data. Insert into table1 values( CAST(col1

How do I find indexes that have statistics_norecompute = ON

会有一股神秘感。 提交于 2021-02-08 12:59:51
问题 I'm looking for a SQL Server 2005 query that will list all the indexes and with their respective STATISTICS_NORECOMPUTE value. I didn't see any obvious value in sysindexes that corresponds to that value. 回答1: The column is no_recompute in sys.stats which says Every index will have a corresponding statistics row with the same name and ID (sys.indexes.object_id = sys.stats.object_id AND sys.indexes.index_id = sys.stats.stats_id), but not every statistics row has a corresponding index. So a JOIN

SQL complex dynamic Pivoting

跟風遠走 提交于 2021-02-08 12:13:57
问题 Hi I am trying in SQL Server the pivoting for the following table REFID | COL1 | COL2 | Sequence 1 abc cde 1 1 lmn rst 2 1 kna asg 3 2 als zkd 2 2 zpk lad 1 I want the output as COLNAME REFID | 1 | 2 | 3 COL1 1 abc lmn kna COL2 1 cde rst asg COL1 2 zpk als null COL2 2 lad zkd null The number of columns in the original table are known but the number of rows are not known. Can any one help 回答1: In order to get the final result, you can use the PIVOT function but first I would unpivot your col1

Query to convert exponential number to float in SQL Server

丶灬走出姿态 提交于 2021-02-08 06:35:46
问题 I am using SELECT CAST('5E-05' AS float) result = 0.00005 and it is not working. Help. https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=5E-05+to+decimal 回答1: Provide correct output for this so that we test and throw few more sample data. Try this, SELECT CONVERT(decimal(18,8), CAST('5E-05' AS FLOAT)) 来源: https://stackoverflow.com/questions/36914381/query-to-convert-exponential-number-to-float-in-sql-server

SQL TRY-CATCH and the missing columns

吃可爱长大的小学妹 提交于 2021-02-07 19:44:22
问题 I have the following (SQL Server 2005) DECLARE @L_ID_FOO_BAR INT BEGIN TRY SELECT @L_ID_FOO_BAR = IDFOO FROM BAR WHERE IDFOO = 5 END TRY BEGIN CATCH SELECT @L_ID_FOO_BAR = NULL END CATCH in the BAR table I could have (on old databases) or not (in some more recennt databases) the IDFOO column. So, for the missing IDFOO column I'd like to leave @L_ID_FOO_BAR = NULL, in case if that column exists select the respective IDFOO. However, when executing the script on bases without that column I

SQL TRY-CATCH and the missing columns

点点圈 提交于 2021-02-07 19:43:34
问题 I have the following (SQL Server 2005) DECLARE @L_ID_FOO_BAR INT BEGIN TRY SELECT @L_ID_FOO_BAR = IDFOO FROM BAR WHERE IDFOO = 5 END TRY BEGIN CATCH SELECT @L_ID_FOO_BAR = NULL END CATCH in the BAR table I could have (on old databases) or not (in some more recennt databases) the IDFOO column. So, for the missing IDFOO column I'd like to leave @L_ID_FOO_BAR = NULL, in case if that column exists select the respective IDFOO. However, when executing the script on bases without that column I

Why does my tempdb reset permissions when the server is rebooted?

我的梦境 提交于 2021-02-07 11:40:11
问题 The past two times we have rebooted our sql server, our website has gone down. The reason appears to be because the tempdb is getting recreated and the ASPState user is losing permission to read/write to the tempdb (it is an ASP site and session data is stored in the sql server) This was not a problem until about two weeks ago. Does anyone know how I can prevent the sql server from resetting tempdb permissions after a reboot? Or why this only started happening recently? We are using MS SQL

SQL script to change all table references in all stored procedures

十年热恋 提交于 2021-02-05 09:27:46
问题 I have created a new database with copies of existing tables but changed the names of these tables, is there a SQL script that I can run (maybe using SysObjects) to change all references to these tables in all stored procedures? 回答1: DO NOT RELY ON INFORMATION_SCHEMA.ROUTINES because ROUTINE_DEFINITION is only nvarchar(4000) . You need to sys.sql_modules where definition is nvarchar(max) try any of these to find the procedure that you need to modify: SELECT DISTINCT LEFT(s.name+'.'+o.name,