<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>oue&#039;s profile &#187; SQL Server</title>
	<atom:link href="http://www.aspgod.com/category/sql-server/feed" rel="self" type="application/rss+xml" />
	<link>http://www.aspgod.com</link>
	<description>AI algorithm graphics programming blog Firefox ff</description>
	<lastBuildDate>Fri, 20 Jan 2012 16:59:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Setup Timestamp to Table in SQL Server</title>
		<link>http://www.aspgod.com/sql-server/setup-timestamp-to-table-in-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/setup-timestamp-to-table-in-sql-server.html#comments</comments>
		<pubDate>Fri, 03 Jun 2011 09:01:05 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[create date]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/?p=568</guid>
		<description><![CDATA[ปกติแล้วเกือบทุก table จะต้องการใช้ Timestamp ส่วนมากจะ insert ใส่กันไปเองด้วย coding หรือ stored procedure แต่ก็มีวิธีที่ทำให้เราไม่ต้องเข้าไปยุ่งกับมันเลย เพราะยังไงเวลาที่ต้องการ stamp ก็คือเวลาปัจจุบันอยู่แล้ว 1. เริ่มแรกให้เราสร้าง field ที่เป็นประเภท datetime 2. เซ็ต Column Properties ให้ Default Value เป็น getdate() เพื่อเป็นการ auto timestamp 3. ให้ลอง insert ข้อมูลโดยไม่ใส่ create_date ก็จะพบว่าผลลัพธ์ถูกใส่ timestamp มาให้แล้วโดยอัตโนมัติ หวังว่าข้อมูลนี้คงมีประโยชน์ไม่มากก็น้อยนะครับ No related posts. Related posts brought to you by Yet Another Related Posts Plugin.
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>ปกติแล้วเกือบทุก table จะต้องการใช้ Timestamp ส่วนมากจะ insert ใส่กันไปเองด้วย coding หรือ stored procedure แต่ก็มีวิธีที่ทำให้เราไม่ต้องเข้าไปยุ่งกับมันเลย เพราะยังไงเวลาที่ต้องการ stamp ก็คือเวลาปัจจุบันอยู่แล้ว</p>
<p>1. เริ่มแรกให้เราสร้าง field ที่เป็นประเภท datetime<br />
<img class="aligncenter size-full wp-image-569" title="date_time_field" src="http://www.aspgod.com/wp-content/uploads/2011/06/date_time_field.png" alt="" width="347" height="109" /></p>
<p>2. เซ็ต Column Properties ให้ Default Value เป็น getdate() เพื่อเป็นการ auto timestamp<br />
<img class="aligncenter size-full wp-image-570" title="auto_timestamp" src="http://www.aspgod.com/wp-content/uploads/2011/06/auto_timestamp.png" alt="" width="251" height="151" /></p>
<p>3. ให้ลอง insert ข้อมูลโดยไม่ใส่ create_date ก็จะพบว่าผลลัพธ์ถูกใส่ timestamp มาให้แล้วโดยอัตโนมัติ<br />
<img class="aligncenter size-full wp-image-571" title="insert_timestamp" src="http://www.aspgod.com/wp-content/uploads/2011/06/insert_timestamp.png" alt="" width="436" height="32" /><br />
<img src="http://www.aspgod.com/wp-content/uploads/2011/06/result_insert_timestamp1.png" alt="" title="result_insert_timestamp" width="247" height="134" class="aligncenter size-full wp-image-576" /></p>
<p><span style="color: #800000;"><strong>หวังว่าข้อมูลนี้คงมีประโยชน์ไม่มากก็น้อยนะครับ</strong></span></p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/setup-timestamp-to-table-in-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Sensitive SQL Query with SQL Server</title>
		<link>http://www.aspgod.com/sql-server/case-sensitive-sql-query-with-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/case-sensitive-sql-query-with-sql-server.html#comments</comments>
		<pubDate>Wed, 20 Jan 2010 04:13:33 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[case sensitive]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/?p=414</guid>
		<description><![CDATA[ปกติแล้ว sql server ถ้าเรา select อะไรก็ตามแล้ว where name = &#8216;oue&#8217; ผลลัพธ์ที่ได้มาก็จะมีทั้ง oue, Oue, oUe, ouE เพราะว่า default เป็น non Case Sensitive แต่ถ้าผมต้องการให้ query เฉพาะ &#8216;oue&#8217; ล่ะจะทำอย่างไร ก็ทำตาม code ด้านล่างเลยครับ 1 2 3 select * from user where nickname COLLATE Latin1_General_CS_AS = 'oue' แค่นี้เอง สั้นๆง่ายๆ ครับ No related posts. Related posts brought to you by Yet [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>ปกติแล้ว sql server ถ้าเรา select อะไรก็ตามแล้ว where name = &#8216;oue&#8217; ผลลัพธ์ที่ได้มาก็จะมีทั้ง oue, Oue, oUe, ouE เพราะว่า default เป็น non Case Sensitive แต่ถ้าผมต้องการให้ query เฉพาะ &#8216;oue&#8217; ล่ะจะทำอย่างไร ก็ทำตาม code ด้านล่างเลยครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">select</span> <span style="color: #008000;">*</span>
<span style="color: #0600FF; font-weight: bold;">from</span> user
<span style="color: #0600FF; font-weight: bold;">where</span> nickname COLLATE Latin1_General_CS_AS <span style="color: #008000;">=</span> <span style="color: #666666;">'oue'</span></pre></td></tr></table></div>

<p>แค่นี้เอง สั้นๆง่ายๆ ครับ</p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/case-sensitive-sql-query-with-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ROW_NUMBER() in sql server 2005</title>
		<link>http://www.aspgod.com/sql-server/row_number-in-sql-server-2005.html</link>
		<comments>http://www.aspgod.com/sql-server/row_number-in-sql-server-2005.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 02:33:05 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[count row]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[row_num]]></category>
		<category><![CDATA[sub query]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=384</guid>
		<description><![CDATA[ปกติเวลาที่เราต้องการ select ของโดยกำหนดไว้ว่าต้องไม่เกิน 10 row นะ ก็จะใช้ 1 select top 10 * from table1 แต่ถ้าบอกว่า ต้องการ select ของโดยกำหนดว่า เอา row ที่ 10 &#8211; 20 เริ่มจะสงสัยละว่าทำอย่างไร เพราะ sql server กำหนดได้แค่ว่าไม่ให้เกินกี่ตัว แต่โชคดีที่ sql server 2005 มี ROW_NUMBER() ให้ใช้ (เพิ่งมีใน 2005) วิธีใช้ก็ตามนี้เลยครับ 1 2 3 4 select ROW_NUMBER&#40;&#41; OVER&#40;order by ViewId asc&#41; as ROW_NUMBER , ViewId , TopicShow [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>ปกติเวลาที่เราต้องการ select ของโดยกำหนดไว้ว่าต้องไม่เกิน 10 row นะ ก็จะใช้</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">select</span> top <span style="color: #FF0000;">10</span> <span style="color: #008000;">*</span> <span style="color: #0600FF; font-weight: bold;">from</span> table1</pre></td></tr></table></div>

<p>แต่ถ้าบอกว่า ต้องการ select ของโดยกำหนดว่า เอา row ที่ 10 &#8211; 20 เริ่มจะสงสัยละว่าทำอย่างไร เพราะ sql server กำหนดได้แค่ว่าไม่ให้เกินกี่ตัว แต่โชคดีที่ sql server 2005 มี ROW_NUMBER() ให้ใช้ (เพิ่งมีใน 2005) วิธีใช้ก็ตามนี้เลยครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">select</span> ROW_NUMBER<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> OVER<span style="color: #008000;">&#40;</span>order by ViewId asc<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ROW_NUMBER
, ViewId
, TopicShow
<span style="color: #0600FF; font-weight: bold;">from</span> mView</pre></td></tr></table></div>

<p>sql ด้านบนนี้จะได้เลขของ row มา ทำให้เราสามารถทำ sub query เพื่อเลือกเฉพาะ row ที่เราต้องการได้</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">select</span> <span style="color: #008000;">*</span>
<span style="color: #0600FF; font-weight: bold;">from</span> <span style="color: #008000;">&#40;</span>
<span style="color: #0600FF; font-weight: bold;">select</span> ROW_NUMBER<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> OVER<span style="color: #008000;">&#40;</span>order by ViewId asc<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ROW_NUMBER
, ViewId
, TopicShow
<span style="color: #0600FF; font-weight: bold;">from</span> mView <span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> news
<span style="color: #0600FF; font-weight: bold;">where</span> ROW_NUMBER <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span>
and ROW_NUMBER <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">20</span></pre></td></tr></table></div>

<p>เพิ่มเติมอีกเล็กน้อย เพื่อทำให้ query รวดเร็วยิ่งขึ้น จาก sql ข้างบนจะเห็นว่า sub query จะ select ของทุกอย่างใน table ก่อน แล้วค่อยให้ query ด้านนอก filter อีกครั้ง ซึ่งเปลือง process พอสมควร จึงแก้ไขด้วยการใส่ top 20 ลงไปใน sub query เพื่อลด process กันหน่อย</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">select</span> <span style="color: #008000;">*</span>
<span style="color: #0600FF; font-weight: bold;">from</span> <span style="color: #008000;">&#40;</span>
<span style="color: #0600FF; font-weight: bold;">select</span> top <span style="color: #FF0000;">20</span> ROW_NUMBER<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> OVER<span style="color: #008000;">&#40;</span>order by ViewId asc<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ROW_NUMBER
, ViewId
, TopicShow
<span style="color: #0600FF; font-weight: bold;">from</span> mView <span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> news
<span style="color: #0600FF; font-weight: bold;">where</span> ROW_NUMBER <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span>
and ROW_NUMBER <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">20</span></pre></td></tr></table></div>

<p>ใครเข้ามาอ่านแล้วเห็นว่ามีประโยชน์ก็ comment หน่อยนะคับ (หาเสียงกันสุดๆ ^ ^)<br />
ไว้พบกันใหม่กับ post ต่อไป<br />
ถ้าไม่พบปัญหา คงไม่ได้มาเขียนบทความให้อ่านแน่ๆเลย &gt;.&lt;</p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/row_number-in-sql-server-2005.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Change Owner Name for SQL Server (Table, Stored Procedures)</title>
		<link>http://www.aspgod.com/sql-server/change-owner-name-for-sql-server-table-stored-procedures.html</link>
		<comments>http://www.aspgod.com/sql-server/change-owner-name-for-sql-server-table-stored-procedures.html#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:35:36 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[change owner name]]></category>
		<category><![CDATA[owner name]]></category>
		<category><![CDATA[stored procedures]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=369</guid>
		<description><![CDATA[Use this command below to change the owner name of table or stored procedures in SQL Server 1 2 exec sp_changeobjectowner 'TABLE_NAME', 'dbo' exec sp_changeobjectowner 'STORED_PROCEDURES_NAME', 'dbo' No related posts. Related posts brought to you by Yet Another Related Posts Plugin.
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Use this command below to change the owner name of table or stored procedures in SQL Server</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">exec sp_changeobjectowner <span style="color: #666666;">'TABLE_NAME'</span>, <span style="color: #666666;">'dbo'</span>
exec sp_changeobjectowner <span style="color: #666666;">'STORED_PROCEDURES_NAME'</span>, <span style="color: #666666;">'dbo'</span></pre></td></tr></table></div>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/change-owner-name-for-sql-server-table-stored-procedures.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alter table statement in sql server</title>
		<link>http://www.aspgod.com/sql-server/alter-table-statement-in-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/alter-table-statement-in-sql-server.html#comments</comments>
		<pubDate>Sat, 01 Aug 2009 18:54:08 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[change column in table]]></category>
		<category><![CDATA[change type in table]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=281</guid>
		<description><![CDATA[If you want to add some column in a table. You might use the sql server management tool or other tools to manage this with their&#8217;s easy UI. But if you are in some situation that haven&#8217;t the management tools to manage the table. You might use the sql script to do that. It&#8217;s call [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you want to add some column in a table. You might use the sql server management tool or other tools to manage this with their&#8217;s easy UI. But if you are in some situation that haven&#8217;t the management tools to manage the table. You might use the sql script to do that. It&#8217;s call Alter Table.</p>
<p>Actually I found a problem with web sql management tools (with parallels Plesk panel) because when I change a column in table then the owner of table will change and the application in this server cann&#8217;t connected with this table. This&#8217;s my serious problem. -*-</p>
<p>Hope you enjoin to use this solution.</p>
<p><strong>To add a column in table :</strong><br />
ALTER TABLE table_name<br />
ADD column_name datatype</p>
<p><strong>To drop a column in table :</strong><br />
ALTER TABLE table_name<br />
DROP COLUMN column_name</p>
<p><strong>To change a datatype of column in table :</strong><br />
ALTER TABLE table_name<br />
ALTER COLUMN column_name datatype</p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/alter-table-statement-in-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross server query (Sql Server)</title>
		<link>http://www.aspgod.com/sql-server/cross-server-query-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/cross-server-query-sql-server.html#comments</comments>
		<pubDate>Mon, 22 Jun 2009 04:35:12 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[cross database]]></category>
		<category><![CDATA[cross server]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=229</guid>
		<description><![CDATA[When using sql server query crossing 2 or more server in the same query. try this select * from OPENDATASOURCE( &#8216;SQLOLEDB&#8217;, &#8216;Data Source=111.111.111.11;User ID=uid;Password=pass&#8217; ).DBName.dbo.TableName But if you query crossing 2 or more database form 1 server. try this select * from DBName.dbo.TableName No related posts. Related posts brought to you by Yet Another Related [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>When using sql server query crossing 2 or more server in the same query.<br />
try this</p>
<blockquote><p>
select * from OPENDATASOURCE(<br />
&#8216;SQLOLEDB&#8217;,<br />
&#8216;Data Source=111.111.111.11;User ID=uid;Password=pass&#8217;<br />
).DBName.dbo.TableName
</p></blockquote>
<p>But if you query crossing 2 or more database form 1 server.<br />
try this</p>
<blockquote><p>
select * from DBName.dbo.TableName
</p></blockquote>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/cross-server-query-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select table name from Sql Server</title>
		<link>http://www.aspgod.com/sql-server/select-table-name-from-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/select-table-name-from-sql-server.html#comments</comments>
		<pubDate>Mon, 15 Jun 2009 04:09:04 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[table name]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=215</guid>
		<description><![CDATA[try this : select * from sysobjects where xtype = &#8216;U&#8217; you will get all table name in database that you focus and try select * from sysobjects where xtype = &#8216;U&#8217; order by uid asc, name asc you will get the name list like the left tab of sql server No related posts. Related [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>try this :</p>
<blockquote><p>
select * from sysobjects where xtype = &#8216;U&#8217;
</p></blockquote>
<p>you will get all table name in database that you focus</p>
<p>and try</p>
<blockquote><p>
select * from sysobjects where xtype = &#8216;U&#8217; order by uid asc,  name asc
</p></blockquote>
<p>you will get the name list like the left tab of sql server</p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/select-table-name-from-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Single quote problem in SQL Server</title>
		<link>http://www.aspgod.com/sql-server/single-quote-problem-in-sql-server.html</link>
		<comments>http://www.aspgod.com/sql-server/single-quote-problem-in-sql-server.html#comments</comments>
		<pubDate>Thu, 04 Jun 2009 04:43:56 +0000</pubDate>
		<dc:creator>aspgod</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[single quote]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.aspgod.com/myprofile/?p=196</guid>
		<description><![CDATA[It is a query string problem when you are coding like this string sqlstr = &#8220;insert into UserMember (Id, Name) values(1, &#8221; + txtName.Text + &#8220;)&#8221; if the txtName.Text has the value like this 1. testname&#8217; 2. &#8216;testname 3. testn&#8217;ame etc. the error message will be found - Unclosed quotation mark before the character string [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>It is a query string problem when you are coding like this</p>
<p>string sqlstr = &#8220;insert into UserMember (Id, Name) values(1, &#8221; + txtName.Text + &#8220;)&#8221;</p>
<p>if the txtName.Text has the value like this<br />
1. testname&#8217;<br />
2. &#8216;testname<br />
3. testn&#8217;ame<br />
etc.</p>
<p>the error message will be found<br />
- Unclosed quotation mark before the character string &#8216;)<br />
- Incorrect syntax near &#8216;testname&#8217;<span id="more-196"></span></p>
<p>Change txtName.Text to txtName.Text.replace(&#8220;&#8216;&#8221;, &#8220;&#8221;&#8221;) will solve this problem. Double single qoute will appear the empty space then no effect with query string and no error.</p>
<p>But you won&#8217;t found the problem while using Store Procedure because SP has no necessary with single quote when passing the parameter to SP like</p>
<blockquote><p>set ANSI_NULLS ON<br />
set QUOTED_IDENTIFIER ON<br />
GO<br />
ALTER PROCEDURE [mobile].[GetCampaign]<br />
@v_campaignId int=null<br />
AS<br />
BEGIN<br />
SET NOCOUNT ON;</p>
<p>select *<br />
from Campaign<br />
where CampaignId = &#8216;@v_campaignId&#8217; &#8212; no single quote will be right<br />
END</p></blockquote>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.aspgod.com/sql-server/single-quote-problem-in-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

