Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 11:44:28
|
| hello,I want to write an sql query which will also return me empty row of a table.Here is what I want.this query returns me 6 resultsSELECT [TOCHSLevel],[TOCHSPrefixText],[TOCHSCounterStyleID],[ShowTOCElement] FROM TOCHSElement where TOCHeaderSchemaID=148And results are as followTOCHSLevel TOCHSPrefix TOCHSCounterStyleID ShowTOCElement1 Bob 87 12 Joe 86 13 Fred 83 14 Sue 81 15 Moe 89 16 0 1Now I am writing the same query,but now two tables are involved.The table TOCNumberingSchemas have only 2 columns TOCHSCounterStyleID and TOCNumberingSchemaNameAnd this is my querySELECT e.TOCHSLevel,e.TOCHSPrefixText,t.TOCNumberingSchemaName,e.ShowTOCElement FROM TOCHSElement e,TOCNumberingSchemas t where TOCHeaderSchemaID=148 AND e.TOCHSCounterStyleID=t.TOCHSCounterStyleID;And here is the resultTOCHSLevel TOCHSPrefix TOCNumberingSchemaName ShowTOCElement1 Bob test_abc 12 Joe Testing 13 Fred Roman Numerals 14 Sue Lower Case Letters 15 Moe Jim's Test 1I want my output to me like the following in gridview because I will be performing update/delete of themTOCHSLevel TOCHSPrefix TOCNumberingSchemaName ShowTOCElement1 Bob test_abc 12 Joe Testing 13 Fred Roman Numerals 14 Sue Lower Case Letters 15 Moe Jim's Test 16 None 1Now I can do one thing is to insert NONE with TOCHSCounterSTyleID 0 in the TOCNumberin gSchemas,but TOCHSCounterSTyleID is an identity column and is not allowing me to insert that.Please helpThank You |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-30 : 11:47:55
|
FROM TOCHSElement eleft join TOCNumberingSchemas t on e.TOCHSCounterStyleID=t.TOCHSCounterStyleIDshould helpWebfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-30 : 12:10:57
|
| also use COALESCE() or ISNULL() to convert NULL values to None |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 13:50:36
|
| Hey I am new to this can you tell me how to use these two functions to make it to none. Thanks for your help,Left join solved my problem. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-30 : 13:59:05
|
| [code]SELECT e.TOCHSLevel,e.TOCHSPrefixText,COALESCE(t.TOCNumberingSchemaName,'None'),e.ShowTOCElement FROM TOCHSElement eLEFT JOIN TOCNumberingSchemas t ON t.TOCHeaderSchemaID=148 AND e.TOCHSCounterStyleID=t.TOCHSCounterStyleID[/code] |
 |
|
|
|
|
|
|
|