background preloader

Codingsway

Facebook Twitter

Codings Way

Codings Way Source Code for Software developer

How do I add PHP code/file to HTML(.html) files? - Codings Way. PHP regular expressions: No ending delimiter '^' found in - Codings Way. Disabling Strict Standards in PHP 5.4 - Codings Way. I’m currently running a site on php 5.4, prior to this I was running my site on 5.3.8. Unfortunately, php 5.4 combines E_ALL and E_STRICT, which means that my previous setting for error_reporting does not work now. My previous value was E_ALL & ~E_NOTICE & ~E_STRICT Should I just enable values one at a time? I have far too many errors and the files contain too much code for me to fix. Answer As the commenters have stated the best option is to fix the errors, but with limited time or knowledge, that’s not always possible.

In your php.ini change error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT If you don’t have access to the php.ini, you can potentially put this in your .htaccess file: php_value error_reporting 30711 This is the E_ALL value (32767) and the removing the E_STRICT (2048) and E_NOTICE (8) values. error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); One of those should help you be able to use the software. Formatting Phone Numbers in PHP - Codings Way. Page redirect after certain time PHP - Codings Way. PHP is not recognized as an internal or external command in command prompt - Codings Way. How to increase the execution timeout in php? - Codings Way. Is there a way to use shell_exec without waiting for the command to complete? - Codings Way. Altering a column: null to not null - Codings Way. Search of table names - Codings Way. Insert multiple rows WITHOUT repeating the “INSERT INTO …” part of the statement? - Codings Way.

I know I’ve done this before years ago, but I can’t remember the syntax, and I can’t find it anywhere due to pulling up tons of help docs and articles about “bulk imports”. Here’s what I want to do, but the syntax is not exactly right… please, someone who has done this before, help me out INSERT INTO dbo.MyTable (ID, Name) VALUES (123, 'Timmy'), (124, 'Jonny'), (125, 'Sally') I know that this is close to the right syntax. I might need the word “BULK” in there, or something, I can’t remember. Any idea? I need this for a SQL Server 2005 database. DECLARE @blah TABLE ( ID INT NOT NULL PRIMARY KEY, Name VARCHAR(100) NOT NULL ) INSERT INTO @blah (ID, Name) VALUES (123, 'Timmy') VALUES (124, 'Jonny') VALUES (125, 'Sally') SELECT * FROM @blah I’m getting Incorrect syntax near the keyword 'VALUES'.

Answer INSERT INTO dbo.MyTable (ID, Name) SELECT 123, 'Timmy' UNION ALL SELECT 124, 'Jonny' UNION ALL SELECT 125, 'Sally' SQL Server Profiler - How to filter trace to only display events from one database? - Codings Way. Optimistic vs. Pessimistic locking - Codings Way. I understand the differences between optimistic and pessimistic locking. Now could someone explain to me when I would use either one in general? And does the answer to this question change depending on whether or not I’m using a stored procedure to perform the query?

But just to check, optimistic means “don’t lock the table while reading” and pessimistic means “lock the table while reading.” Answer Optimistic Locking is a strategy where you read a record, take note of a version number (other methods to do this involve dates, timestamps or checksums/hashes) and check that the version hasn’t changed before you write the record back. If the record is dirty (i.e. different version to yours) you abort the transaction and the user can re-start it. This strategy is most applicable to high-volume systems and three-tier architectures where you do not necessarily maintain a connection to the database for your session. Optimistic vs. Pessimistic locking - Codings Way. How to pass an array into a SQL Server stored procedure - Codings Way. How to pass an array into a SQL Server stored procedure? For example, I have a list of employees. I want to use this list as a table and join it with another table. But the list of employees should be passed as parameter from C#.

Answer SQL Server 2008 (or newer) First, in your database, create the following two objects: CREATE TYPE dbo.IDList AS TABLE ( ID INT ); GO CREATE PROCEDURE dbo.DoSomethingWithEmployees @List AS dbo.IDList READONLY AS BEGIN SET NOCOUNT ON; SELECT ID FROM @List; END GO Now in your C# code: SQL Server 2005 If you are using SQL Server 2005, I would still recommend a split function over XML. CREATE FUNCTION dbo.SplitInts ( @List VARCHAR(MAX), @Delimiter VARCHAR(255) ) RETURNS TABLE AS RETURN ( SELECT Item = CONVERT(INT, Item) FROM ( SELECT Item = x.i.value('(.

Now your stored procedure can just be: CREATE PROCEDURE dbo.DoSomethingWithEmployees @List VARCHAR(MAX) AS BEGIN SET NOCOUNT ON; SELECT EmployeeID = Item FROM dbo.SplitInts(@List, ','); END GO. How to return only the Date from a SQL Server DateTime datatype - Codings Way. Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00:00:00.000 How can I get that? Answer On SQL Server 2008 and higher, you should CONVERT to date: SELECT CONVERT(date, getdate()) On older versions, you can do the following: SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, @your_date)) for example SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) gives me Pros: No varchar<->datetime conversions requiredNo need to think about locale As suggested by Michael Use this variant: SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) select getdate() SELECT DATEADD(hh, DATEDIFF(hh, 0, getdate()), 0) SELECT DATEADD(hh, 0, DATEDIFF(hh, 0, getdate())) SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, getdate())) SELECT DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0) SELECT DATEADD(mm, 0, DATEDIFF(mm, 0, getdate())) SELECT DATEADD(yy, DATEDIFF(yy, 0, getdate()), 0) SELECT DATEADD(yy, 0, DATEDIFF(yy, 0, getdate())) Output:

Where is SQL Profiler in my SQL Server 2008? - Codings Way. How to use GROUP BY to concatenate strings in SQL Server? - Codings Way. Cannot truncate table because it is being referenced by a FOREIGN KEY constraint? - Codings Way. Using MSSQL2005, can I truncate a table with a foreign key constraint if I first truncate the child table (the table with the primary key of the FK relationship)? I know that I can either Use a DELETE without a where clause and then RESEED the identity (or)Remove the FK, truncate the table, and recreate the FK. I thought that as long as I truncated the child table before the parent, I’d be okay without doing either of the options above, but I’m getting this error: Cannot truncate table ‘TableName’ because it is being referenced by a FOREIGN KEY constraint.

Answer Correct; you cannot truncate a table which has an FK constraint on it. Typically my process for this is: Drop the constraintsTrunc the tableRecreate the constraints. (All in a transaction, of course.) Of course, this only applies if the child has already been truncated. The original poster determined WHY this is the case; see this answer for more details. Function to return only alpha-numeric characters from string? - Codings Way. I’m looking for a php function that will take an input string and return a sanitized version of it by stripping away all special characters leaving only alpha-numeric. I need a second function that does the same but only returns alphabetic characters A-Z. Any help much appreciated. Answer Warning: Note that English is not restricted to just A-Z.

Try this to remove everything except a-z, A-Z and 0-9: $result = preg_replace("/[^a-zA-Z0-9]+/", "", $s); If your definition of alphanumeric includes letters in foreign languages and obsolete scripts then you will need to use the Unicode character classes. Try this to leave only A-Z: $result = preg_replace("/[^A-Z]+/", "", $s); The reason for the warning is that words like résumé contains the letter é that won’t be matched by this. Efficiently convert rows to columns in sql server - Codings Way. I’m looking for an efficient way to convert rows to columns in SQL server, I heard that PIVOT is not very fast, and I need to deal with lot of records. This is my example: ------------------------------- | Id | Value | ColumnName | ------------------------------- | 1 | John | FirstName | | 2 | 2.4 | Amount | | 3 | ZH1E4A | PostalCode | | 4 | Fork | LastName | | 5 | 857685 | AccountNumber | ------------------------------- This is my result: --------------------------------------------------------------------- | FirstName |Amount| PostalCode | LastName | AccountNumber | --------------------------------------------------------------------- | John | 2.4 | ZH1E4A | Fork | 857685 | --------------------------------------------------------------------- How can I build the result?

Answer There are several ways that you can transform data from multiple rows into columns. Using PIVOT In SQL Server you can use the PIVOT function to transform the data from rows to columns: See Demo. See Demo. See Demo. Effect of NOLOCK hint in SELECT statements - Codings Way. I guess the real question is: If I don’t care about dirty reads, will adding the with (NOLOCK) hint to a SELECT statement affect the performance of: the current SELECT statementother transactions against the given table Example: Select * from aTable with (NOLOCK) Answer Yes, a select with NOLOCK will complete faster than a normal select.Yes, a select with NOLOCK will allow other queries against the effected table to complete faster than a normal select. Why would this be? NOLOCK typically (depending on your DB engine) means give me your data, and I don’t care what state it is in, and don’t bother holding it still while you read from it. You should be warned to never do an update from or perform anything system critical, or where absolute correctness is required using data that originated from a NOLOCK read.

You really have no way to know what the state of the data is. Always use the NOLOCK hint with great caution and treat any data it returns suspiciously. Copy tables from one database to another in SQL Server - Codings Way. Get the list of stored procedures created and / or modified on a particular date? - Codings Way. How do I obtain a Query Execution Plan in SQL Server? - Codings Way.

In Microsoft SQL Server how can I get a query execution plan for a query / stored procedure? Answer There are a number of methods of obtaining an execution plan, which one to use will depend on your circumstances. Usually you can use SQL Server Management Studio to get a plan, however if for some reason you can’t run your query in SQL Server Management Studio then you might find it helpful to be able to obtain a plan via SQL Server Profiler or by inspecting the plan cache.

Method 1 – Using SQL Server Management Studio SQL Server comes with a couple of neat features that make it very easy to capture an execution plan, simply make sure that the “Include Actual Execution Plan” menu item (found under the “Query” menu) is ticked and run your query as normal. If you are trying to obtain the execution plan for statements in a stored procedure then you should execute the stored procedure, like so: exec p_Example 42 Method 2 – Using SHOWPLAN options SET <<option>> OFF See also: INSERT INTO @TABLE EXEC @query with SQL Server 2000 - Codings Way. Is it true that SQL Server 2000, you can not insert into a table variable using exec? I tried this script and got an error message EXECUTE cannot be used as a source when inserting into a table variable. declare @tmp TABLE (code varchar(50), mount money) DECLARE @q nvarchar(4000) SET @q = 'SELECT coa_code, amount FROM T_Ledger_detail' INSERT INTO @tmp (code, mount) EXEC sp_executesql (@q) SELECT * from @tmp If that true, what should I do?

Answer N.B. – this question and answer relate to the 2000 version of SQL Server. In later versions, the restriction on INSERT INTO @table_variable ... EXEC ... were lifted and so it doesn’t apply for those later versions. You’ll have to switch to a temp table: CREATE TABLE #tmp (code varchar(50), mount money) DECLARE @q nvarchar(4000) SET @q = 'SELECT coa_code, amount FROM T_Ledger_detail' INSERT INTO #tmp (code, mount) EXEC sp_executesql (@q) SELECT * from #tmp A table variable behaves like a local variable. What is the meaning of the prefix N in T-SQL statements and when should I use it? - Codings Way.

I have seen prefix N in some insert T-SQL queries. Many people have used N before inserting the value in a table. I searched, but I was not able to understand what is the purpose of including the N before inserting any strings into the table. INSERT INTO Personnel.Employees VALUES(N'29730', N'Philippe', N'Horsford', 20.05, 1), What purpose does this ‘N’ prefix serve, and when should it be used? Answer It’s declaring the string as nvarchar data type, rather than varchar You may have seen Transact-SQL code that passes strings around using an N prefix. To quote from Microsoft: Prefix Unicode character string constants with the letter N. If you want to know the difference between these two data types, see this SO post: What is the difference between varchar and nvarchar?

T-SQL Substring - Last 3 Characters - Codings Way. Is there a SELECT … INTO OUTFILE equivalent in SQL Server Management Studio? - Codings Way. How to rename a table in SQL Server? - Codings Way. C# Equivalent of SQL Server DataTypes - Codings Way. For the following SQL Server datatypes, what would be the corresponding datatype in C#? Exact Numerics bigint numeric bit smallint decimal smallmoney int tinyint money Approximate Numerics float real Date and Time date datetimeoffset datetime2 smalldatetime datetime time Character Strings char varchar text Unicode Character Strings nchar nvarchar ntext Binary Strings binary varbinary image Other Data Types cursor timestamp hierarchyid uniqueidentifier sql_variant xml table (source: MSDN) Answer The following table lists Microsoft SQL Server data types, their equivalents in the common language runtime (CLR) for SQL Server in the System.Data.SqlTypes namespace, and their native CLR equivalents in the Microsoft .NET Framework.

UPDATE and REPLACE part of a string - Codings Way. Is there a combination of “LIKE” and “IN” in SQL? - Codings Way. In SQL I (sadly) often have to use “LIKE” conditions due to databases that violate nearly every rule of normalization. I can’t change that right now. But that’s irrelevant to the question. Further, I often use conditions like WHERE something in (1,1,2,3,5,8,13,21) for better readability and flexibility of my SQL statements. Is there any possible way to combine these two things without writing complicated sub-selects? I want something as easy as WHERE something LIKE ('bla%', '%foo%', 'batz%') instead of this: WHERE something LIKE 'bla%' OR something LIKE '%foo%' OR something LIKE 'batz%' I’m working with SQl Server and Oracle here but I’m interested if this is possible in any RDBMS at all.

Answer There is no combination of LIKE & IN in SQL, much less in TSQL (SQL Server) or PLSQL (Oracle). Both Oracle and SQL Server FTS implementations support the CONTAINS keyword, but the syntax is still slightly different: Oracle: WHERE CONTAINS(t.something, 'bla OR foo OR batz', 1) > 0 SQL Server: Reference: Sql query to return differences between two tables - Codings Way. I am trying to compare two tables, SQL Server, to verify some data. I want to return all the rows from both tables where data is either in one or the other.

In essence, I want to show all the discrepancies. I need to check three pieces of data in doing so, FirstName, LastName and Product. I’m fairly new to SQL and it seems like a lot of the solutions I’m finding are over complicating things. I don’t have to worry about NULLs. I started by trying something like this: SELECT DISTINCT [First Name], [Last Name], [Product Name] FROM [Temp Test Data] WHERE ([First Name] NOT IN (SELECT [First Name] FROM [Real Data])) I’m having trouble taking this further though. SELECT td. But I keep getting 0 results back, when I know that there is at least 1 row in td that is not in d. Ok, I think I figured it out. SELECT [First Name], [Last Name] FROM [Temp Test Data] AS td WHERE (NOT EXISTS (SELECT [First Name], [Last Name] FROM [Data] AS d WHERE ([First Name] = td. Answer. How to check if a database exists in SQL Server? - Codings Way. How to set a default value for an existing column - Codings Way.

How to execute .sql file using powershell? - Codings Way. Sql server invalid object name - but tables are listed in SSMS tables list - Codings Way. Export SQL query data to Excel - Codings Way. SQL Server: How to Join to first row - Codings Way. How to check if a stored procedure exists before creating it - Codings Way. Login to Microsoft SQL Server Error: 18456 - Codings Way. Sql server Get the FULL month name from a date - Codings Way. Error, string or binary data would be truncated when trying to insert - Codings Way. How do you specify a different port number in SQL Management Studio? - Codings Way.

Combine two tables that have no common fields - Codings Way. How do I change db schema to dbo - Codings Way. Finding duplicate rows in SQL Server - Codings Way. SQL Server: Multiple table joins with a WHERE clause - Codings Way. SQL MAX of multiple columns? - Codings Way. Jquery lose focus event - Codings Way. Add to Array jQuery - Codings Way. JQuery - $ is not defined - Codings Way. PHP cURL custom headers - Codings Way. Make var_dump look pretty - Codings Way. jQuery count child elements - Codings Way. Default value in Doctrine - Codings Way. Bootstrap Alert Auto Close - Codings Way. Create XML in Javascript - Codings Way. Track mouse position - Codings Way JQuery Track mouse position.

Php static function - Codings Way. What is console.log? - Codings Way. Getter and Setter? - Codings Way. Change image onmouseover - Codings Way. JavaScript override methods - Codings Way. On - window.location.hash - Change? - Codings Way. Angular and debounce - Codings Way. PHP - Codings Way. Promise.all().then() resolve? - Codings Way. Javascript form validation with password confirming - Codings Way. What is the best way to paginate results in SQL Server - Codings Way. How do I drop a foreign key constraint only if it exists in sql server? - Codings Way. Alternatives to REPLACE on a text or ntext datatype - Codings Way.

DateTime.MinValue and SqlDateTime overflow - Codings Way. Difference between left join and right join in SQL Server - Codings Way. How to do a case sensitive search in WHERE clause (I'm using SQL Server)? - Codings Way. How can I determine installed SQL Server instances and their versions? - Codings Way. Get first day of week in SQL Server - Codings Way. Add default value of datetime field in SQL Server to a timestamp - Codings Way. Mssql '5 (Access is denied.)' error during restoring database - Codings Way. MySQL query String contains - Codings Way. jQuery AJAX submit form - Codings Way. Mouse position Archives - Codings Way. Track mouse position - Codings Way JQuery Track mouse position. Window.onload vs $(document).ready() - Codings Way. What is console.log? - Codings Way.

What is console.log?

How to convert an image to base64 encoding? - Codings Way. Codings Way Source Code for Software developer -